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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Incorrect form load issue

(0) ShareShare
ReportReport
Posted on by 958

Hi All,

I have a HTML web resource to launch the selected account form for account creation and other one is for load the account form on which the record is created.

But, the JavaScript web resource which is used to reopen the account record within the particular account form (in which created) is not working as expected.

Somehow it launch the incorrect form and the field which i am using to separate the form name is also get update.

Is there any way to not update a field once it has some value or Need to update the code?

Code is given below: - 

function onLoad()
{
//if the form is update form
if (Xrm.Page.ui.getFormType()==2){
// variable to store the name of the form
var lblForm;
// get the value picklist field
var relType = Xrm.Page.getAttribute("new_formname").getValue();
// switch statement to assign the form to the picklist value
//change the switch statement based on the forms numbers and picklist values
switch (relType) {
case 'Site':
lblForm = "Site";
break;
case 'NoPileups - Site':
lblForm = "NoPileups - Site";
break;
case 'Account - Franchise':
lblForm = "Account - Franchise";
break;
case 'Distributor':
lblForm = "Distributor";
break;
case 'Organization':
lblForm = "Organization";
break;
case'Sage-Organization':
lblForm = "Sage-Organization";
break;
default:
lblForm = "Sage-Site";
}
//check if the current form is form need to be displayed based on the value
if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items) {
var item = items[i];
var itemId = item.getId();
var itemLabel = item.getLabel()
if (itemLabel == lblForm) {
//navigate to the form
item.navigate();
return;
} //endif
} //end for
} //endif
}
}//endif

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Shakti ,

    I am sorry , could  not understand your question clearly. Just try to debug your code and see why its redirecting wrong forms , as you wrote a check with form type "if(Xrm.Page.ui.getFormType()==2)" which means only update forms or existing record your code will execute.

    In order to display correct form without code  by default you need to set form order.

    www.marksgroup.net/.../

    Also is it possible to give some more details about your requirement.

  • Shakti Singh Rajput Profile Picture
    958 on at

    Hi Goutam Das,

    Thanks for the response!

    Actually, AutoSave is enabled for all the forms and because of this, it changes the value of the "new_formname" field.

    Like, If I launch an account record which is created under A form(account entity form) and after this if I launch another record which is created under B form(account entity form), then for a couple of seconds it launches the  "A" account form and when it tries to launch the correct form first the previous form get to save because of auto-save functionality and that save update the field value of "new_formname" from "B"(actual value) to "A"(previous record's form name) and then the record is finally launched within the Form "A" but the actual form was "B".

    It all happens because of the auto-save. If I disable the auto-save and launch the records with different forms a pop-up is appeared for unsaved changes just because of the "new_formname" field and if I hit Discard Changes then it launches the correct form all the time. But my client don't want that Pop-Up window.

    Please suggest!

    I am using below script which is implemented OnSave Event on the account form to set the form name in a field:-

    function SetFormName()

    {

    var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

    //alert(formName);

    Xrm.Page.getAttribute("new_formname").setValue(formName);

    }

  • talk2.gauravb Profile Picture
    120 on at

    Hi,

    Changing the form while page is getting loaded via javascript will give a glitch to the user as form may load twice. I will recommend to write a plugin on pre-retrieve for account entity and write the logic in it.

  • Shakti Singh Rajput Profile Picture
    958 on at

    Can you please clarify which kind of logic you want me to write?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans