sc_req_item Variables VS sc_task Variables - How to synchronize???

G24
Kilo Sage

Hello geniuses.

 

I'm having trouble figuring out how to handle Requested Item Variables and Task Variables.

 

I have 4 variables, A, B, C, and D.  They are all numbers.  A is filled out up front upon submission of the Catalog Item.

 

B and C are filled in by provisioners who work on tasks in parallel.  Since they are working in parallel, I made B ONLY available to one Task, and I made C ONLY  available in another task.  (I found out the hard way that if I did NOT do that isolation, then I could end up in a "race condition" where one team's updates could affect the other team's variables.)

 

What I want to do is this:  When a provisioner updates value B or value C, I want for that update to be reflected in my running total D.  And I want this to show up asap at the Requested Item level.  Currently that is happening for items B and C, but I need to attach some code somewhere to total up A B and C, and populate D.

 

Where and how do I do that?  I'm confused about which Variables I should be updating.  Are the Requested Item Variables separate from the Task Variables?  Are they stored in a separate table?  Which tables?  Do I need to use an After Update business rule or something?

 

Please help.  Thank you greatly.

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage
Tera Sage

Hi @G24 ,

 

You can create a business rule on SC Task table to achieve this.

 

When to run : Async

operation : update

Condition :

DanishBhairag2_0-1695368140752.png

 

 

Choose the correct catalog item here (you can dot walk from request item field) & mention the task short description for both task contain catalog item variables B & C.

Note Try to keep the Short Description bit Unique(add some special characters) as we are creating BR on sc task table & it should only trigger for our requirement.

 

In advanced section u can try the below script:

 

 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('sys_id',current.request_item);
	gr.query();
	if(gr.next()){
		if(gr.variables.b == '')
			gr.variables.b = '0';
		if(gr.variables.c == '')
			gr.variables.c = '0';
		gr.variables.d = parseInt(gr.variables.a) + parseInt(gr.variables.b) + parseInt(gr.variables.c); // assuming the values in variable a,b & c would be string 
		gr.update();
	}

})(current, previous);

 

 

 

Please mark my response Helpful & Accepted if it helps you resolve your query.

 

Thanks,

Danish

 

View solution in original post

3 REPLIES 3

-O-
Kilo Patron
Kilo Patron

In the title you talk about sc_task, so I assume when you talk about tasks, you mean Catalog Tasks.

If yes, then one can say - assuming the OOB generally implemented scenario - that both Requested Items and Catalog Tasks display - read and update the same variables.

So what you could do is to create an after update Business Rule (or Flow - if you prefer) on the table that stores the variable values (sc_item_option) - preferably asynchronous one, that looked up the sibling variables (A, B, C), computed their sum, than looked up the Total variable (D) and updated it.

Revanth Karra
Tera Expert

Dear Geoffrey,

 

Hope you're doing great!

 

@G24  Correct! Requested Item Variables and Task Variables are separate and stored in separate tables.

Requested Item Variables are stored in the sc_req_item table. Task Variables are stored in the sc_task table.

 

To update the Requested Item Variable D when a provisioner updates a Task Variable, you can use an After Update business rule.

The After Update business rule will be triggered whenever a Task Variable is updated. The business rule can then use the sc_req_item table to update the Requested Item Variable D.

 

EXAMPLE:

After Update business rule that you can use:

 

 

current.variables.D = current.variables.A + current.variables.B + current.variables.C;
current.update();

 

 

This business rule will update the Requested Item Variable D to be the sum of the Requested Item Variables A, B, and C.

You can attach this business rule to the sc_task table.

Another way to update the Requested Item Variable D when a provisioner updates a Task Variable is to use a workflow.

You can create a workflow that is triggered whenever a Task Variable is updated. The workflow can then use the sc_req_item table to update the Requested Item Variable D.

 

EXAMPLE:

Workflow that you can use:

 

 

Start
|
Update Requested Item Variable D
|
End

 

 

The Update Requested Item Variable D action will update the Requested Item Variable D to be the sum of the Requested Item Variables A, B, and C.

You can attach this workflow to the sc_task table.

Which method you choose to use depends on your specific needs and requirements. If you need to update the Requested Item Variable D immediately after a Task Variable is updated, then you should use an After Update business rule. If you need to update the Requested Item Variable D as part of a more complex workflow, then you should use a workflow.

 

Kindly, please mark my solution as Helpful/Correct, if applicable. If I could help you with your Query then, please hit the Thumb Icon and mark as Correct!!!

 

Thanks & Regards, 

Revanth. K

Product Test Automation Engineer

Danish Bhairag2
Tera Sage
Tera Sage

Hi @G24 ,

 

You can create a business rule on SC Task table to achieve this.

 

When to run : Async

operation : update

Condition :

DanishBhairag2_0-1695368140752.png

 

 

Choose the correct catalog item here (you can dot walk from request item field) & mention the task short description for both task contain catalog item variables B & C.

Note Try to keep the Short Description bit Unique(add some special characters) as we are creating BR on sc task table & it should only trigger for our requirement.

 

In advanced section u can try the below script:

 

 

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('sys_id',current.request_item);
	gr.query();
	if(gr.next()){
		if(gr.variables.b == '')
			gr.variables.b = '0';
		if(gr.variables.c == '')
			gr.variables.c = '0';
		gr.variables.d = parseInt(gr.variables.a) + parseInt(gr.variables.b) + parseInt(gr.variables.c); // assuming the values in variable a,b & c would be string 
		gr.update();
	}

})(current, previous);

 

 

 

Please mark my response Helpful & Accepted if it helps you resolve your query.

 

Thanks,

Danish