web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / Office Scripts Return ...
Copilot Studio
Unanswered

Office Scripts Return Value to Bot from Excel

(0) ShareShare
ReportReport
Posted on by

I have a flow where I am trying to return a value that is being calculated based off two inputs received from PVA bot to excel.  I enter in the Specialty and the Percentile value and it returns the dollar value.  When I just use the excel results dynamic action it works but as soon as I try to dollar format it it fails to bring in anything to the PVA bot.

 

Here is my script:

 

 

async function main(workbook: ExcelScript.Workbook, specialty: string, perc: string): Promise<string> {
 // Access the worksheet named 'Percentile Input'.
 let worksheet = workbook.getWorksheet('Percentile Input');

 // Set the medical specialty in cell D2 based on the variable 'specialty'.
 let specialtyCell = worksheet.getRange('D2');
 specialtyCell.setValue(specialty);

 // Set the percentile value in cell D11 based on the variable 'perc'.
 let percCell = worksheet.getRange('D11');
 percCell.setValue(parseFloat(perc.replace(/[^0-9.]+/g, ""))); // Remove any non-numeric characters before setting.

 // Retrieve the calculated percentile from cell I11.
 let percentileCell = worksheet.getRange('I11');
 let percentileValue = percentileCell.getValue();

 // Format the percentile value as a dollar value.
 let formattedValue = `$${percentileValue.toFixed(2)}`; // Assuming two decimal places for cents

 // Log the formatted value to the console.
 console.log("Formatted Value:", formattedValue);

 // Return the formatted percentile value as a string.
 return formattedValue;
}

 

 

 

Here is my flow

wherdzik_0-1709681079303.png

 

I am trying to format the value that comes from the output of the script but the bot fails. 

 

 

formatNumber(float(outputs('Run_script')?['body/result']), '$#,##0.00')
 

 

 

 
 
wherdzik_2-1709681198180.png

 

 

When I change to result it works:

wherdzik_3-1709681221784.png

 

 wherdzik_4-1709681251544.png

 

wherdzik_1-1709681120672.png

 

I don't understand why it doesn't like the formatting, is it because it is coming in as a string? Is there anyway I can format this so I can bring it to the bot?  

 

I think it something silly that I cannot figure out.

I tried this as well and it didnt work. 

 

 

formatNumber(float(outputs('Run_script')?['body/result']), '0,0.00', 'en-us')

 

 

Categories:
I have the same question (0)
  • Verified answer
    v-bofeng-msft Profile Picture
    on at

    Hi @wherdzik  , 

     

    I've made a test, and encountered the problem you mentioned. Please choose 'Text' as the type of output and your formula will work(formatNumber(float(outputs('Run_script')?['body/result']), '0,0.00', 'en-us')).

     vbofengmsft_0-1709716105557.png

    vbofengmsft_2-1709716204315.png

     

    Best Regards,
    Bof

     

     

     

     

  • wherdzik Profile Picture
    on at

    I tried your solution, and it did not work but then I tried the Format data by examples again and that seem to work.  So switching it to text made a difference.  This is what I used.😄

     

     

    formatNumber(float(outputs('Run_script')?['body/result']), '$#,##0.00')

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Copilot Studio

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 265 Super User 2025 Season 2

#2
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 240 Super User 2025 Season 2

#3
S-Venkadesh Profile Picture

S-Venkadesh 101 Moderator

Last 30 days Overall leaderboard