Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Error de Script- Where it's?

Posted on by Microsoft Employee

cer.png

Hello everybody! 

I've a question about it ^

I know that we've "system scripts" and "user scripts" (that we made)... When I make my scripts, somes days afthers I get this error but somes times.... For example in 3 month I get that only 4 times and today I was able to make a picture (because the others 3 was with others Users, this time was to me).

My dude is: Where is this "Anonymous Function"? I've reseaching in all sites and don't look any function with this name.... and what I must do with this?? (desactivate this script??? or add the fields that this script need in invisible section?).

Thanks.

*This post is locked for comments

  • Kevin Grech Profile Picture
    Kevin Grech 380 on at
    RE: Error de Script- Where it's?

    If you're talking about the error in the original post, check my suggestion. This error has opened my eyes to the 'Promise' type (not supported by IE)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error de Script- Where it's?

    Thanks Goutam, I've made all changes in all Stages and Branch Stages.

    Because I've the same logic (the then success and error) when I want move from Stage to Stage.

    I don't know if in the future the error will never get again xD! but I've seen that the "refresh" was more fast than usual (so... I think that it work better).

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error de Script- Where it's?

    So in my script I must do this Change? (yeah... I repply before but I didn't see that your answers was charging yet...)

    Actual Script:

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    function successCallback()
    {
    	Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    }
    function errorCallback() { console.log("error"); } Xrm.Page.data.entity.save().then(successCallback, errorCallback);
    }


    ----------------------
    function successCallback()
    {
    if(Xrm.Page.ui.getFormType() == 1 && status == "invalid") //You can add condition here
    { Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    } } function errorCallback() {
       if(Xrm.Page.ui.getFormType() == 1 && status == "invalid") //You can add condition here
    {
    console.log("error");
    }
    }
    if(Xrm.Page.ui.getFormType() == 1 && status == "invalid")
    {
    Xrm.Page.data.entity.save().then(successCallback, errorCallback);
    }

    All in the same sentence? (Inside of "If (StageName === "Etapa 1-...")??
    Or I must do what? (Two Option)

    1)Add Outside the If Stages Sentence : Success and Error CallBacks functions and Inside the If Stage Sentence: Xrm.Page.data.entity.save()....
    2)Add Inside the If Stages Sentence : Success, Error and Xrm.Page.data.entity.save().....





  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Error de Script- Where it's?

    Hi Maurizio,

    Please try with this -

            function Mainfunction() {
    
                if (StageName === "Etapa 1- Identificar Prospecto") {
                    var backstage = Xrm.Page.data.process.getSelectedStage();
                    var manic = Xrm.Page.getAttribute("mk_manact_inicial").getValue();
                    var reuini = Xrm.Page.getAttribute("mk_reunion_inicial").getValue();
                    var onHoldUno = Xrm.Page.getAttribute("mk_on_hold").getValue();
                    var PerdidaUno = Xrm.Page.getAttribute("mk_perdida").getValue();
                    Xrm.Page.getAttribute("mk_fase_proceso").setValue(StageAName);
                    // Pediremos que en St1 (inicial) setee los SetR# a Falsos
                    var SetR1 = Xrm.Page.getAttribute("mk_activar_requerido_1").setValue(false);
                    var SetR2 = Xrm.Page.getAttribute("mk_activar_requerido_2").setValue(false);
                    var SetR3 = Xrm.Page.getAttribute("mk_activar_requerido_3").setValue(false);
                    var SetR4 = Xrm.Page.getAttribute("mk_activar_requerido_4").setValue(false);
                    var SetR5 = Xrm.Page.getAttribute("mk_activar_requerido_5").setValue(false);
                    var SetR1 = Xrm.Page.getAttribute("mk_activar_requerido_1").getValue();
                    var SetR2 = Xrm.Page.getAttribute("mk_activar_requerido_2").getValue();
                    var SetR3 = Xrm.Page.getAttribute("mk_activar_requerido_3").getValue();
                    var SetR4 = Xrm.Page.getAttribute("mk_activar_requerido_4").getValue();
                    var SetR5 = Xrm.Page.getAttribute("mk_activar_requerido_5").getValue();
                    console.log("SetR1" + SetR1);
                    console.log("SetR2" + SetR2);
                    console.log("SetR3" + SetR3);
                    console.log("SetR4" + SetR4);
                    console.log("SetR5" + SetR5);
    
                    var StageIdUno = StageSelect.getId();
                    console.log("Id Stage1" + StageIdUno);
    
                    // Guardaremos var Desca1 mk_descalifica_1
                    //var Desca1 = Xrm.Page.getAttribute("mk_descalifica_1").getValue();
    
                    if ((manic == false) || (reuini == false)) {
                        moveToNext = false;
                    }
                    if (moveToNext) {
    
                        //Move to the next stage y VISTA
    
                        Xrm.Page.data.process.moveNext(function (status) {
    
                            console.log(status);
    
                            console.log(Xrm.Page.ui.getFormType());
    
                            if (Xrm.Page.ui.getFormType() == 1 && status == "invalid") {
    
                                Xrm.Page.data.entity.save().then(successCallback, errorCallback);                         
    
                            }
    
                            else if (status == "success") {
    
                                Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    
                            }
    
                        });
    
                    }
    
                }
            }
    
    
    
            function successCallback() {
                Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
            }
    
    
    
    
            function errorCallback() {
                console.log("error");
            }


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error de Script- Where it's?

    I must add it before the part where scripts has "then" ? Or I can add it in the end? Thanks

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Error de Script- Where it's?

    Hi Maurizio,

    Could you please  add below function outside your main function instead of writing inside of the function. You can not add any condition to execute any function in this way.

    function successCallback()
    {
    if(-----) //You can add condition here
    { Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    } } function errorCallback() {
       if(-----) //You can add condition here
    {
    console.log("error");
       }
    }

    Try to write first without condition  and just mover from inside main function to out side of the main function.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error de Script- Where it's?

    So... I must change this:

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

    function successCallback()

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    function errorCallback()

    {

    console.log("error");

    }

    }

    In to:

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    function successCallback()
    {
    	Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    }
    
    function errorCallback()
    {
    	console.log("error");
    
    }
    Xrm.Page.data.entity.save().then(successCallback, errorCallback);
    }

    I've used the first because I read a post that the owner use that for "refresh" the form when we are "OnSaved" event.
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error de Script- Where it's?

    Oh yes, this script is in "OnSaved" and "OnLoad", so User can get move to the next stage if the conditions are true.

    Or it's a bad idea and only I need keep it in "OnSaved"?

  • Suggested answer
    Kevin Grech Profile Picture
    Kevin Grech 380 on at
    RE: Error de Script- Where it's?

    If this is the actual script, check out msdn.microsoft.com/.../dn481607.aspx

    That save function in red does not return a promise. You need to use Xrm.Page.data.save()

    Edit: This Microsoft article highlights the difference https://msdn.microsoft.com/en-us/library/gg334720.aspx#BKMK_save

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Error de Script- Where it's?

    Hi, You need to create the function first. Then only assigned it to the then function:

    function successCallback()
    {
    	Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    }
    
    function errorCallback()
    {
    	console.log("error");
    
    }
    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans