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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

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
    Microsoft Employee 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Copilot Studio

#1
Valantis Profile Picture

Valantis 704

#2
Vish WR Profile Picture

Vish WR 249

#3
Haque Profile Picture

Haque 244

Last 30 days Overall leaderboard