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

How can i copy the ordered guide variable to request table

BalaLalitha Gun
Tera Contributor

Hi,

 

We have a reference variable on the ordered guide Development which is a reference variable.

I have created a custom field on Request table same as Development which is a reference field same as ordered guide variable.

 

Now, when a user selects Development from Ordered guide form then after the request creation the variable needs to be copied to Request table Development field.

 

I have created a BR. But the field is not populating.

 

How can I achieve this?

Thank you,

5 REPLIES 5

-O-
Kilo Patron

Order guide variables are not saved anywhere when submitted/ordered/requested.

You have to define the same variable on one (or all - to be safe) of the catalog items included and choose Variable Cascading option on the order guide.

Yashsvi
Kilo Sage

Hi @BalaLalitha Gun,

 

To ensure the value from the reference variable `Development` on the ordered guide is copied to a custom reference field on the Request table, you need to create a Business Rule (BR) or a Script Include that runs after the Request is created. Here’s a concise guide to achieving this:

Steps:

1. Create a Reference Field on the Request Table:
- Ensure you have created a reference field on the 'sc_request' table (Request table) that matches the

'Development' reference variable.

2. Create a Business Rule:
- Create a Business Rule that runs after the Request is inserted to copy the value from the ordered guide variable to the custom field on the Request table.

Business Rule:

1. Business Rule Configuration:
- Name: Copy Development Variable to Request
- Table: 'sc_request'
- When: After
- Insert: Checked
- Update: Optional, based on your requirement

 

2. Script:

 

(function executeRule(current, previous /*null when async*/) {
// Check if the current record has a reference to the catalog request item
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
while (gr.next()) {
// Get the value of the Development variable from the catalog item
var devValue = gr.variables.development;
if (devValue) {
current.u_development = devValue; // Assuming u_development is the custom field on the Request table
current.update(); // Update the current request record with the new value
}
}
})(current, previous);


By following these steps, you should be able to successfully copy the `Development` reference variable value from the ordered guide to a custom field on the Request table.

 

Thank you, please make helpful if you accept the solution. 

HI Yashsvi,

 

I have tried your solution. But the value is showing as undefined.

 

Actually, the development field is not showing on the RITM variables. 
How can i achieve this?

Thank you,

 

Community Alums
Not applicable

Hi @BalaLalitha Gun ,

 

It looks like the issue is with the variable you have to set the development. Ensure its correct.
It would be great if you can share the BR and the dictionary value of the field development, this would help us troubleshoot your issue better.

 

Here is an updated BR as per Yashsvi.

(function executeRule(current, previous /*null when async*/) {
    // Ensure the variable is available and can be accessed from RITM
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('request', current.sys_id);
    gr.query();
    
    while (gr.next()) {
        // Access the variable from the RITM
        var devValue = gr.variables.development; // Replace 'development' with the actual variable name
        gs.log('Development Value: ' + devValue); // Debug log
        
        if (devValue) {
            // Copy the value to the request field
            current.u_development = devValue; // Ensure 'u_development' is the correct field on the Request table
            gs.log('Setting Development Field: ' + current.u_development); // Debug log
            current.update(); // Update the request record with the new value
        }
    }
})(current, previous);

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar