cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rmprecioso
Frequent Visitor

Office Script Error: "Script not found. It may have been unshared or deleted"

 I am working on  a Power Automate Run Script process which takes a number as a parameter and outputs a JSON object. I am having an error of "Script not found. It may have been unshared or deleted" whenever someone other than me is running the flow. The flow is triggered from PowerApps.

 

Here are the things I have done so far:

1. Made sure that workbook is shared and has edit (the person is even the owner now of the folder and the file itself)

2. Made sure that the script is shared enabled also

3. I even shared the power automate ownership to the person

4. Tested with other person with same permission configuration

5. Tested to run the script by its own both by me and that person and it's running okay except if the person run it through power automate

rmprecioso_0-1606812967895.png

 

10 REPLIES 10
v-litu-msft
Community Support
Community Support

Hi @rmprecioso,

 

What's the script do? Do you mind sharing the script?

How about trying to delete the script then recreate a new one to test?

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rmprecioso
Frequent Visitor

hi @v-litu-msft 

What the script does is to create an array of object, shuffle it, and get the top items in the list. 

I tried recreating it as well.

Here is the script:

function main(workbook: ExcelScript.Workbook, top: number = 1😞 Result {
    let selectedSheet = workbook.getWorksheet("Participant");

 

    let selectedRange = selectedSheet.getRange("A1").getSurroundingRegion().getValues();

 

    let pool: Winner[] = [];

 

    for (let i = 1; i < selectedRange.length; i++) {
        let range = selectedRange[i];
        let upinO = range[3].toString();
        pool.push({
            upin: upinO.substring(0,upinO.indexOf('@')),
            name: range[4].toString(),
            department: range[5].toString(),
            eligibility: range[7].toString(),
        });
    }

 

    var shuffledPool = shuffle(pool.filter(isEligible));

 

    console.log(shuffledPool);
    console.log(shuffledPool.slice(0, top));

 

    let result = {
      eligibleCount: shuffledPool.length,
      winners :shuffledPool.slice(0, top)
    };
    
    console.log(result);
    return result;

 

}

 

interface Result{
  winners: Winner[];
  eligibleCount: number;
}

 

interface Winner {
    name: string;
    upin: string;
    department: string;
    eligibility: string;
}

 

function isEligible(element, index, array) {
  return (element.eligibility == 'ok');
}

 

function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;

 

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

 

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

 

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }

 

  return array;
}
Yutao
Microsoft
Microsoft

Hi @rmprecioso ,

 

Unfortunately, at this moment, the Run script action can only access and execute the scripts created by yourself but not shared scripts.

 

Therefore, when you're sharing a flow with other people, you'll need to also share the original connection (the one created under your name) embedded in that flow. The original connection can make sure the action will run on-behalf-of you so it can have access to your script.

 

This is the default sharing behavior in Power Automate so presumably it should work for you. But can you please double check if the embedded connection is still pointing to your account?

 

Screenshot - 12_14_2020 , 10_32_59 AM.png

 

Yutao

Neha2904
Frequent Visitor

Hi Yutao,
I added the other user as co-owner to the flow, and yet the flow is failing at Run Script stage. Any suggestions?

Serbay
Resolver I
Resolver I

Hey Neha, 
Were you able to find the fail reason? I'm facing the same issue now. 
Regards,
Serbay

Yutao
Microsoft
Microsoft

@Serbay , @rmprecioso , @Neha2904

 

Please see if the steps below can solve the problem:

 

1. On the details page of the flow, click the "Edit" button next to "Run only users":

 

Screenshot - 2_26_2021 , 9_04_49 AM.png

 

2. On the "Manage run-only permissions" panel, make sure to select "Use this connection (...)" from the "Connection Used" dropdown list.

 

Screenshot - 2_26_2021 , 9_03_54 AM.png

 

 

3. Save the settings

 

4. Ask another user to try it again.

 

These settings will make sure the flow runs on-behalf-of the original owner of the flow.

 

Hope this helps!

 

Yutao

Serbay
Resolver I
Resolver I

Hi, Yutao 
Thanks a lot for your response! Definitely, this solution will be helpful on some of my flows. But Unfortunately, there is no option as "Run only users for me" since I use the trigger as "PowerApps". I guess this is valid only with some of the triggers.
Do you have any idea how can we make sure a flow which has a PowerApps trigger will run on the behalf of the owner, not the user?

Thanks a lot!
Regards,
Serbay

Yutao
Microsoft
Microsoft

Hey @Serbay ,

 

Yes indeed it seems the "Run-only" settings only supports very few triggers (the manual button trigger being one).

I did a bit experiments and figured out a solution that worked for me -

 

* Firstly, you'll need to create all your flows and PowerApps apps within a "Solution". You can create a new solution from "Solutions/New solution":

Solutions.png

 

* Within this new solution, create a button-triggered flow that runs Office Scripts. Let's call it "Child flow". Please note this flow requires to have a last action to respond to a PowerApp or flow.

Child flow.png

 

* Configure this child flow with run-only users settings as described in my previous response. Make sure to choose "Use this connection ...".

 

* Within the same solution, create another flow with the PowerApps trigger. This flow will be triggered by your PowerApps app. In this flow, add a step to run the child flow you've just created above:

Parent flow.png

 

* Within the same solution, create your PowerApps app. Configure your PowerApps button to run the second flow (the parent flow).

 

* Now share the PowerApps app with another user, ask them to try it out, and see if the Run script action in the child flow can work properly.

 

Hope this can also work for you!

 

Yutao

Serbay
Resolver I
Resolver I

Hi, Yutao 
I really appreciate your help and responses. I have a single obstacle now, How can we pass the output of one of the actions from PowerApps triggered flow into child flow? I need to use the body of the parse JSON action in child flow.

 

Inked156589619_730391071172072_8078457381364585211_n_LI.jpg

Inked156433490_749795979067248_3609838408370198964_n_LI.jpg

 

Best Regards,
Serbay






Hey @Serbay -

 

Please see if this works:

 

* In the child flow, add a text input (or whatever input type you need) to the manual trigger. Let's call it "Input". And pass that input value to the consuming actions after it. For example, here I'm passing it directly to the Run script action:

Yutao_2-1614793485700.png

 

* In the parent flow (the PowerApps triggered flow), a new argument named "Input" to run the Child Flow will show up.

Yutao_1-1614792883243.png

 

-Yutao

 

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Users online (64,081)