- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:01 AM
(function executeRule(current, previous /*null when async*/ ) {
gs.print(current.variables.u_software_name); // this prints undefined.
})(current, previous);
I have catalog item which has a sub catalog task, the workflow of the catalog item add u_software_name variable to the sub task.
The business rule prints its value upon the value changes in the form.
BUT, the business rule prints Undefined when it's triggered upon the submission of the catalog item.
Is this by design as variables are injected after sc_task record is created first?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 04:04 AM
Hi @Jake Jeon ,
Yes, this is by design as the variables are injected after the sc_task record is created. When a catalog item is submitted, the sc_request and sc_task records are first created, and then the variables are populated in the sc_task record through the workflow.
If you want to access the value of the u_software_name variable in the business rule upon submission, you can try adding a condition in the business rule to check if the sc_task record is in the process of being created. You can use the 'gs.isInteractive()' method to check if the business rule is being executed in an interactive session, and then use the 'gs.action' property to determine the action being performed.
For example:
(function executeRule(current, previous /*null when async*/) {
if(gs.isInteractive() && gs.action == 'insert') {
// Code to access variable value goes here
gs.print(current.variables.u_software_name);
}
})(current, previous);
This should ensure that the business rule only tries to access the variable value once it has been populated in the sc_task record.
If my response helps you to resolve the issue close the question by ✅Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 04:04 AM
Hi @Jake Jeon ,
Yes, this is by design as the variables are injected after the sc_task record is created. When a catalog item is submitted, the sc_request and sc_task records are first created, and then the variables are populated in the sc_task record through the workflow.
If you want to access the value of the u_software_name variable in the business rule upon submission, you can try adding a condition in the business rule to check if the sc_task record is in the process of being created. You can use the 'gs.isInteractive()' method to check if the business rule is being executed in an interactive session, and then use the 'gs.action' property to determine the action being performed.
For example:
(function executeRule(current, previous /*null when async*/) {
if(gs.isInteractive() && gs.action == 'insert') {
// Code to access variable value goes here
gs.print(current.variables.u_software_name);
}
})(current, previous);
This should ensure that the business rule only tries to access the variable value once it has been populated in the sc_task record.
If my response helps you to resolve the issue close the question by ✅Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 04:09 AM
I well understood, thank you mate.