Relationship Script

GMoon
Kilo Sage

Hi all,

I have a requirement to show Requested Items as a Related List on our Environment form, based on the name of the Environment selected against the Catalog Item that forms the Request. 
For example, if the Cat Item Variable selected on the Requested Item is 'Server A' and matches the name value on the respective Environment form, I want these Requests to populate against the Related List.

Cat Item = 'Enable Environments (On Demand)'
Cat Item Variable = 'Please select the Environment to enable.'  (Reference field) 

 

Could someone help me formulate the script within the Relationship to automatically bring back these RITM's please?

Thank you.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

A script like this will show RITMs with a reference variable value that equals the displayed record:

 

(function refineQuery(current, parent) {
	current.addEncodedQuery('variables.your_variable_sys_id='+parent.sys_id);
})(current, parent);

 

View solution in original post

3 REPLIES 3

KrishanSharma
Tera Expert

Hi @GMoon,

 

You can create a Relationship record with following configuration:

Applies to Table: Environment [cmdb_ci_environment]

Queries from Table: Requested Item [sc_req_item]

Script:

 

(function refineQuery(current, parent) {
	//Replace YOUR_VARIABLE_SYS_ID with the sys_id of the reference variable that holds the Environment value in your catalog
	current.addEncodedQuery('variables.YOUR_VARIABLE_SYS_ID='+parent.sys_id);
})(current, parent);

 

Hope it helps 🙂

Brad Bowman
Kilo Patron
Kilo Patron

A script like this will show RITMs with a reference variable value that equals the displayed record:

 

(function refineQuery(current, parent) {
	current.addEncodedQuery('variables.your_variable_sys_id='+parent.sys_id);
})(current, parent);

 

Thanks once again Brad, appreciate your time.