tried to pull the stockroom name in a catalog form not working

chercm
Mega Sage

how to update the stockroom name based on the assignment group ? 

 

chercm_0-1706863191273.png

 

 

 

i tried to use this but stockroom field of the form is still blank 

 

i created the business rule on it . 

 

(function executeRule(current, previous /*null when async*/) {
// Check if Assignment Group is set
if (current.assignment_group.getDisplayValue() != '') {
// Query the Stockroom based on Assignment Group
var stockroomGR = new GlideRecord('alm_stockroom');
stockroomGR.addQuery('sys_id', current.assignment_group);
stockroomGR.query();
 
// If a stockroom is found, set the Stockroom field on the catalog form
if (stockroomGR.next()) {
current.stockroom = stockroomGR.getValue('name');
}
}
})(current, previous);
 
chercm_1-1706863374336.png

 

2 ACCEPTED SOLUTIONS

Hi @chercm,

 

Got it. I've spotted a few minor issues based on what you're trying to achieve.

I've tested this on a PDI and can confirm it works as required.

Update the following:

 

Business Rule. When to run: 'before'

 

Business Rule Script: (Ready for you to copy and paste)

(function executeRule(current, previous /*null when async*/ ) {
// Check if Assignment Group is set
if (current.assignment_group.getDisplayValue() != '') {
// Query the Stockroom based on Assignment Group

var stockroomGR = new GlideRecord('alm_stockroom');
stockroomGR.addQuery('assignment_group', current.assignment_group);
stockroomGR.query();

// If a stockroom is found, set the Stockroom field on the catalog form
if (stockroomGR.next()) {
current.u_stockroom = stockroomGR.sys_id;

}
}
})(current, previous);
 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

Hi @chercm ,

 

The reason you need to pass the sys_id when setting the stockroom is because the field is of type reference, meaning that it is actually pointing to another table. In order to set this value, you need to use the sys_id. 

You will however see the name displayed on the form. 

 

Have you seen my latest post? I've checked the script on a PDI and it works as required. Please can you copy and paste my script.

Please also ensure you have the Business Rule to operate 'on before' and check the 'Update' checkbox.

Out of interest, when do you set the assignment group? Do you have an Assignment Rule in operation? Have you implemented the script and changed the Assignment group value manually on the form to ensure the script is at least running?

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

20 REPLIES 20

@Robbie tried what you suggested but the field is still blank , i was looking for the name of the stockroom.

Hi @chercm ,

 

The reason you need to pass the sys_id when setting the stockroom is because the field is of type reference, meaning that it is actually pointing to another table. In order to set this value, you need to use the sys_id. 

You will however see the name displayed on the form. 

 

Have you seen my latest post? I've checked the script on a PDI and it works as required. Please can you copy and paste my script.

Please also ensure you have the Business Rule to operate 'on before' and check the 'Update' checkbox.

Out of interest, when do you set the assignment group? Do you have an Assignment Rule in operation? Have you implemented the script and changed the Assignment group value manually on the form to ensure the script is at least running?

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

@Robbie if some one was to reassign the ticket to another assignment group,  how can i get script to check whether there is available stock based on the variables by the user ? and that it will display error if there are not stock for that location ?

Hi @chercm,

 

I've confirmed the script provided works as requested. Can you confirm this isn't a data issue. Do you have assignment group values set against Stockrooms. Can you share a screenshot similar to the below. It sounds obvious, but please also make sure you test using an assignment group that absolutely has a Stockroom associated with it. (Baseline configuration, the assignment groups are not set)

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

Screenshot 2024-02-02 at 12.28.54.png

Robbie
Kilo Patron
Kilo Patron

 Hi @chercm,

 

You're almost there, you just need to tweak the addQuery statement of your GlideRecord to check against the assignment group rather than the sys_id.

 

Use the below instead:

 

(function executeRule(current, previous /*null when async*/) {
// Check if Assignment Group is set
if (current.assignment_group.getDisplayValue() != '') {
// Query the Stockroom based on Assignment Group
var stockroomGR = new GlideRecord('alm_stockroom');
stockroomGR.addQuery('assignment_group', current.assignment_group);
stockroomGR.query();
 
// If a stockroom is found, set the Stockroom field on the catalog form
if (stockroomGR.next()) {
current.u_stockroom = stockroomGR.sys_id;
}
}
})(current, previous);
 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie