Question
Cox Business Services
US
Last activity: 16 Oct 2018 7:03 EDT
Calling javascript on load of section
We need to run a javascript function on load of a section. The section is not created via HTML. This javascript function is used as we have offline enabled case and we need to call an activity through that. The script has already been included into the harness.
***Edited by Moderator Marissa to update categories***
-
Likes (1)
Arye Caspi -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
US
Hi,
I did some research and could come up with a code which would be called when the section gets loaded.
What it does is there will be a timeout configured which will be called recursively since we don't know how much time the section would take to load. When the particular section(eg: Section name is Sample in m case) get loaded this would terminate.
<script>
$( document ).ready(function() {
jQuery(document).ready(checkContainer);
function checkContainer () {
if($('div[data-node-id="Sample"]').is(':visible')){
console.log("ab");
//Write the code here...
} else {
setTimeout(checkContainer, 50);
}
}
});
</script>
You can write this code in Script file and include it in harness level. Hope it helps.
Regards,
Rachit
Pegasystems Inc.
US
Just to understand your situation
You have an offline enabled app
You want to load a section and call an JS before that ?
a. Are you loading the section from within a flow action ? Is yes, then you can use the preFlowAction JS method to do the needful.
I can provide the syntax for the same
Pegasystems Inc.
US
Syntax for pre Flow action activity :
preFlowAction$<flowactionName> { }
Cox Business Services
US
How do we call this JS method ? If as per our understanding we need to call it from a function that is written in the JS file. Also we have to save the data that is fetched from this function into clipboard so that the moment the section is loaded we are able to see the data set into pyWorkPage which can be used for further calculations.
Pegasystems Inc.
US
Hi,
You can write a function in the non-autogenerated section and call it there. So, it will be called whenever the section gets loaded.
Hope it answers your question.
Regards,
Rachit
-
Vivek Kumar Chinthani Kodikara Genya Megananda
Cox Business Services
US
If we use non-auto generated section then we have to create a the entire section using HTML which is not possible as maintenance for this section will be high. Moreover since it is offline enabled application what ever data we put gets stored in the client cache.
-
Chetan Sama
Pegasystems Inc.
US
I mean what we can do is drop a new section into the current section(Auto-Generated). Now, this newly created section should be non-autogenerated which will have the script code. We could also write script code in userworkform but it would be called on every screen in this scenario.
Also, I'll try to find out if we can capture loading of the section in javascript.
Regards,
Rachit
-
SOLAIYAPPARAJA B
Accepted Solution
Pegasystems Inc.
US
Hi,
I did some research and could come up with a code which would be called when the section gets loaded.
What it does is there will be a timeout configured which will be called recursively since we don't know how much time the section would take to load. When the particular section(eg: Section name is Sample in m case) get loaded this would terminate.
<script>
$( document ).ready(function() {
jQuery(document).ready(checkContainer);
function checkContainer () {
if($('div[data-node-id="Sample"]').is(':visible')){
console.log("ab");
//Write the code here...
} else {
setTimeout(checkContainer, 50);
}
}
});
</script>
You can write this code in Script file and include it in harness level. Hope it helps.
Regards,
Rachit
-
Vivek Kumar
Cox Business Services
US
Yes we have used timeout but we are seeing that the script is getting called next time when we login. In our scenario we have to set some values into pyWorkPage immediately when the cases is opened from the worklist. We are seeing that the value is getting set if the user logs off & logs in again & opens the same work object again. In the script we have called an activity & in the activity we have used log message in which we are trying to check the key of the work object in this format as “Fetched work object key is” +Param.FetchedWO. We are seeing that the first time it is showing only “Fetched work object key” in the log but next time when we open the work object after log off & login we are seeing ”Fetched work object key is” A-B-C WO-123 getting logged & proper value getting set into clipboard.
Pegasystems Inc.
US
I have written "console.log("ab");". Did you try to debug if this is getting printed in the console for the first time? You can try first try in Desktop version since it will be easier. Please note that this will be called only when the section gets loaded.
I could not find any issue with the code. You need to debug this.
Cox Business Services
US
We are able to see in console. We can't test in desktop as we have offline enabled application and clientCache APIs work only on device.
Pegasystems Inc.
US
Since you are able to see the console message, it means that the above script is getting successfully called when the section gets loaded. you probably need to debug the activity now.
Cox Business Services
US
Yes that is what I am trying to say that activity is getting executed for the first time also but the value is getting set when the activity is getting triggered again for the same work object.
Evoke Technologies Private Limited
IN
Create a html fragment and add your js in the fragment (let name be Frag for ex). Just add a label control from basic menu in your section. Inside the label, use include tag like follows :
<pega:include name=" Frag" type="Rule-HTML-Fragment" />
rule-html-fragment is the class where your fragment is being stored