Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Suggested answer

Change Forms via JS

Posted on by 380

Hi Guys,

I've been working today on the following scenario:

We have 3 Case forms (each one for a different Case Origin Type)

form-1.PNG

On each form we have a JS that checks the case origin and based on the value changes the form for the user:

formSelector : used to get the list forms that are in the entity (only if more than 1)
getCurrentItem() : returns the current form rendered to the user (this is most important)
navigate() : it will help(force) to navigate to the form that's selecting

function _onLoad(){

if(Xrm.Page.ui.getFormType() == "2") //doing only on update mode, so only will get the Case Origin

{

                var caseOrigin = Xrm.Page.getAttribute('caseorigincode').getValue();

                var items = Xrm.Page.ui.formSelector.items.get();

                var currentItem = Xrm.Page.ui.formSelector.getCurrentItem();

                for (var it in items) //iterate all the items means forms

                {

                                var form= items[it];

                                var formLabel = form.getLabel(); //get the form label like Email, Phone Call

                                //Check condition Label from Form and the corresponding Case Origin and mainly if its not the Current Selected Form

                                if (formLabel == "Phone Call" && caseOrigin == "1" && currentItem.getLabel() != "Phone Call")

                                {

                                                form.navigate(); //now in this case just navigate

 

                                }

                                else if (formLabel == "Email" && caseOrigin == "2" && currentItem.getLabel() != "Email")

                                {

                                                form.navigate();

                                }

                                else if (formLabel == "Information" && caseOrigin == "3" && currentItem.getLabel() != "Information")

                                {

                                                form.navigate();

                                }

                }

}

}

form2.PNG

But when i load the form or change a value to case origin i get the following error:

form3.PNG

This is the information from the log:

SyntaxError: Unexpected end of input
    at RunHandlerInternal (ORGNAME.dynamics.com/.../ClientApiWrapper.aspx
    at RunHandlers (ORGNAME.dynamics.com/.../ClientApiWrapper.aspx
    at OnScriptTagLoaded (ORGNMAE.dynamics.com/.../ClientApiWrapper.aspx
    at https://ORGNAME.dynamics.com/form/ClientApiWrapper.aspx?ver=1565753557:244:1

error-4.PNG

TypeError: Cannot read property 'Initialize' of undefined
    at eval (eval at RunHandlerInternal (ORGNAME.dynamics.com/.../ClientApiWrapper.aspx, <anonymous>:1:27)
    at RunHandlerInternal (ORGNAME.dynamics.com/.../ClientApiWrapper.aspx
    at RunHandlers (ORGNAME.dynamics.com/.../ClientApiWrapper.aspx
    at OnScriptTagLoaded (ORGNAME.dynamics.com/.../ClientApiWrapper.aspx
    at ORGNAME.dynamics.com/.../ClientApiWrapper.aspx

Anyone has any suggestion where im mistaking?

Thanks in advanced and regards

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Change Forms via JS

    Hi There,

    I would suggest you to add logicalname of attribute in double inverted comma's as mentioned below:

    var caseOrigin = Xrm.Page.getAttribute("caseorigincode").getValue();

    This should work.

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Change Forms via JS

    Hi,

    Based on the errors, it looks like you have some syntax error in your javascript library When I checked your hraed script using an online java script syntax validator, i see some error ( it may be just the formatting here in this thread). You can also check your entire script similary and fix any syntax error.

    js_5F00_illegal.png

    esprima.org/.../validate.html

    Hope this helps.

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