The CreatorCon Call for Content is officially open! Get started here.

Business Rule with Catalog Task Table has undefined Variables upon submission via Service Portal

Jake Jeon
Tera Contributor
(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.

JakeJeon_0-1678957059822.png

 

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?

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage

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

View solution in original post

2 REPLIES 2

Ratnakar7
Mega Sage

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

I well understood, thank you mate.