Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Copilot Studio - General
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:
  • wherdzik Profile Picture
    on at
    Re: Office Scripts Return Value to Bot from Excel

    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')

     

     

  • Verified answer
    v-bofeng-msft Profile Picture
    on at
    Re: Office Scripts Return Value to Bot from Excel

    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

     

     

     

     

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Copilot Studio - General

#1
Artur Stepniak Profile Picture

Artur Stepniak 5 Super User 2025 Season 1

#2
Ekta Gupta Profile Picture

Ekta Gupta 4

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 4 Super User 2025 Season 1

Overall leaderboard