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

  • Shakti Singh Rajput Profile Picture
    958 on at
    RE: Incorrect form load issue

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

  • talk2.gauravb Profile Picture
    120 on at
    RE: Incorrect form load issue

    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
    RE: Incorrect form load issue

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

    }

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Incorrect form load issue

    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.

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!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans