Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

Instance variables are cleared when executing a workflow

Avatar

Level 2

Good morning, I'm encountering a rather unique problem that I can't seem to fix.

 

To make it short I use javascript code which configures schedulers, but when the workflow runs and executes the javascript code it must be restarted for the scheduler modifications to be taken into account. to prevent it from restarting the workflow in a loop I use an instance variable "<variables lastSavedDate="xxxx-xx-xx"/>". The Javascript code will check if the value that I entered in a script variable (var inputDate) is equal to instance.vars.lastSavedDate, if this is the case then it continues processing, if this is not the case then it updates the lastSavedDate variable with the value of inputDate then it restarts the workflow.

 

In theory I think it should work, in practice my instance variable is simply cleared. when I do a logInfo(instance.vars.lastSavedDate), the log returns "undefined" and when I return to the workflow variables there is only "<variables/>" which is entered instead of "< variables lastSavedDate="xxxx-xx-xx"/>" Do you have any idea why it does this and how to fix it?

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hello,

I found a workaround to resolve my issue. As my script updates scheduler parameters as soon as the workflow is launched, I simply add it to the javascript code of my start activity:

activity.mask = 1;

xtk.workflow.Restart(instance.id);

 

This prevents the workflow from looping infinitely. If users want to change the date, they can always do so by reactivating the start activity and modifying the variable values.

I'm not sure this is a best practice but in my case it's functional

View solution in original post

3 Replies

Avatar

Community Advisor

Hi @Ragsthenos ,

Alternatively you can try the below method by creating an Option > storing the last saved date here and calling the value whenever required and updating the last saved date.

create an option (/Administration/Platform/Options/) with name as wkf1LastSavedDate

ParthaSarathy_0-1698661221610.png

In workflow's JavaScript, 

//To call last saved date time from option
vars.wkf1LastSavedDate =  getOption ("wkf1LastSavedDate");

//To update the current time in the option
vars.currentTime = getCurrentDate();
setOption ("wkf1LastSavedDate", vars.currentTime);

Avatar

Level 2

Hi @ParthaSarathy 

 

Unfortunately I cannot use the options because I am working on a workflow template which will be reused several times, and I therefore cannot afford to create a new option for each new workflow created from this template. Thanks for trying to help me. Is it normal for my instance variable to be deleted? I managed to display it once but when I restarted the workflow afterwards, it left me undefined.

Avatar

Correct answer by
Level 2

Hello,

I found a workaround to resolve my issue. As my script updates scheduler parameters as soon as the workflow is launched, I simply add it to the javascript code of my start activity:

activity.mask = 1;

xtk.workflow.Restart(instance.id);

 

This prevents the workflow from looping infinitely. If users want to change the date, they can always do so by reactivating the start activity and modifying the variable values.

I'm not sure this is a best practice but in my case it's functional