Hello Everyone!
Hope all of you are happy. Can anyone tell me why my js web resource runs 2 times when form load? Function will have to trigger when form load.
*This post is locked for comments
Bro actually i created one more JS web resource in which i wanted to insert that code in which BPF change on form load but that web resource do not execute when form load so it cut code from that web resource and injected this web resource in which button disable on certain stage
yes it executed 1 time after commenting all code
Just for trial to check whether this is the root cause or not . In addition you can comment out all the code inside the function and check how many time its executing.
// A namespace defined for the sample code
// As a best practice, you should always define
// a unique namespace for your libraries
var Sdk = window.Sdk || {};
(function () {
// Code to run in the form OnLoad event
this.formOnLoad = function (executionContext) {
console.log("disable button web resource");
//var formContext = executionContext.getFormContext();
//var selectedStage = formContext.data.process.getSelectedStage();
//var selectedStageName = selectedStage.getName();
//if (selectedStageName == "RF Review")
//{
// parent.document.getElementById("stageAdvanceActionContainer").style.display = "none";
// parent.document.getElementById("stageBackActionContainer").style.display = "none";
//}
//console.log("after getting form context");
//var processObj = formContext.data.process.getActiveProcess();
//var processName = processObj.getName();
//console.log("after getting process name");
//console.log(processName);
//console.log("before if");
//if(processName == "Case to Work Order Business Process")
//{
// formContext.data.process.setActiveProcess("f51baaeb-f184-4ffa-bf98-19c2891afa67",callBackFunction);
//}
//console.log("after assigning id");
//formContext.data.entity.save();
//console.log("after save");
}
function callBackFunction(result){
}
}).call(Sdk);
and as i remember before including this line issue js was executing 2 times
but i cannot do this because i have to switch process on form load
Try to remove below line -
formContext.data.process.setActiveProcess("f51baaeb-f184-4ffa-bf98-19c2891afa67",callBackFunction);
After removing this problem is same issue not resolved. It is executing 2 times again.
Hi,
This is because you are calling formContext.data.entity.save(); method inside the onload function. When you are doing Save in onload which is calling Onload functionits expected form will reload again and thats why its getting fired two time .
when you save records that means page will always reload and call all the onload function. For the first time Onload will call and second time when page get saved.
// A namespace defined for the sample code
// As a best practice, you should always define
// a unique namespace for your libraries
var Sdk = window.Sdk || {};
(function () {
// Code to run in the form OnLoad event
this.formOnLoad = function (executionContext) {
console.log("disable button web resource");
var formContext = executionContext.getFormContext();
var selectedStage = formContext.data.process.getSelectedStage();
var selectedStageName = selectedStage.getName();
if (selectedStageName == "RF Review")
{
parent.document.getElementById("stageAdvanceActionContainer").style.display = "none";
parent.document.getElementById("stageBackActionContainer").style.display = "none";
}
console.log("after getting form context");
var processObj = formContext.data.process.getActiveProcess();
var processName = processObj.getName();
console.log("after getting process name");
console.log(processName);
console.log("before if");
if(processName == "Case to Work Order Business Process")
{
formContext.data.process.setActiveProcess("f51baaeb-f184-4ffa-bf98-19c2891afa67",callBackFunction);
}
console.log("after assigning id");
formContext.data.entity.save();
console.log("after save");
}
function callBackFunction(result){
}
}).call(Sdk)
// A namespace defined for the sample code
// As a best practice, you should always define
// a unique namespace for your libraries
var Sdk = window.Sdk || {};
(function () {
// Code to run in the form OnLoad event
this.formOnLoad = function (executionContext) {
console.log("disable button web resource");
var formContext = executionContext.getFormContext();
var selectedStage = formContext.data.process.getSelectedStage();
var selectedStageName = selectedStage.getName();
if (selectedStageName == "RF Review")
{
parent.document.getElementById("stageAdvanceActionContainer").style.display = "none";
parent.document.getElementById("stageBackActionContainer").style.display = "none";
}
console.log("after getting form context");
var processObj = formContext.data.process.getActiveProcess();
var processName = processObj.getName();
console.log("after getting process name");
console.log(processName);
console.log("before if");
if(processName == "Case to Work Order Business Process")
{
formContext.data.process.setActiveProcess("f51baaeb-f184-4ffa-bf98-19c2891afa67",callBackFunction);
}
console.log("after assigning id");
formContext.data.entity.save();
console.log("after save");
}
function callBackFunction(result){
}
}).call(Sdk);
This is not a expected behavior . where did you register your function? is it OOB on-load event ?
Please share your code and screenshot here .
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156