Set RITM Price from Option

leport
Tera Contributor

I have a catalog item with a multiple choice variable for the user to select which license type they are requesting (see variable configuration below.  I want the price on the RITM to be set as the value in the Recurring Price associated with the option the user selects

 

 

leport_0-1736882581842.png

 

How do I set the Price field on the RITM from the option they select?

 

1 ACCEPTED SOLUTION

The issue seems to lie in your script logic and possibly in your understanding of the variable relationship and how question_choice stores data.

Here is a sample query:

 

(function executeRule(current, previous /*null when async*/) {
    // Create a GlideRecord for 'question_choice' table
    var type = new GlideRecord('question_choice');
    
    // Add query to find the correct choice based on question and selected value
    type.addQuery('question', '3D2826f6164707d214384e47eb616d4357'); // Replace with your actual variable sys_id
    type.addQuery('value', current.variables.license_type); // Match the value selected by the user
    
    // Execute the query
    type.query();
    
    // If a matching record is found, retrieve the price
    if (type.next()) {
        var licprice = type.recurring_price; // Ensure you are fetching the correct field (recurring_price in this case)
        current.price = licprice; // Set the price on the RITM
    }
})(current, previous);

 


ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.




ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ


ꜱʀᴇᴇʀᴀᴍ

View solution in original post

11 REPLIES 11

@leport Use a Business Rule on the RITM Table:

Create a Business Rule on the Requested Item (RITM) table.
This Business Rule will dynamically pull the recurring price of the selected variable option and set the price field on the RITM.


ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.




ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ


ꜱʀᴇᴇʀᴀᴍ

I have created an Advanced BR on the sc_req_item table for this particular catalog item but it does not appear to be cooperating.  See script below

 

(function executeRule(current, previous /*null when async*/ ) {
    var type = new GlideRecord('question_choice'); 
    type.addQuery = ('question''3D2826f6164707d214384e47eb616d4357'); 
    type.addQuery = ('value', current.variables.license_type); 
    type.query(); 
   
    if (type.next()) {
        var licprice = type.rec_misc; //get the price from the question value recurring price field
               current.price = licprice;
    }

 

})(current, previous);

The issue seems to lie in your script logic and possibly in your understanding of the variable relationship and how question_choice stores data.

Here is a sample query:

 

(function executeRule(current, previous /*null when async*/) {
    // Create a GlideRecord for 'question_choice' table
    var type = new GlideRecord('question_choice');
    
    // Add query to find the correct choice based on question and selected value
    type.addQuery('question', '3D2826f6164707d214384e47eb616d4357'); // Replace with your actual variable sys_id
    type.addQuery('value', current.variables.license_type); // Match the value selected by the user
    
    // Execute the query
    type.query();
    
    // If a matching record is found, retrieve the price
    if (type.next()) {
        var licprice = type.recurring_price; // Ensure you are fetching the correct field (recurring_price in this case)
        current.price = licprice; // Set the price on the RITM
    }
})(current, previous);

 


ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.




ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ


ꜱʀᴇᴇʀᴀᴍ

Ankur Bawiskar
Tera Patron
Tera Patron

@leport 

you can use after insert BR on sc_req_item table and get the variable's recurring price value and set

what script did you start with and where are you stuck?

check this

Populate RITM Price Field with Catalog String Variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you @Ankur Bawiskar . 

 

Below is the script I have in the BR.  It is not setting the price on the RITM as I would expect it to.

 

 

(function executeRule(current, previous /*null when async*/ ) {
    var type = new GlideRecord('question_choice'); 
    type.addQuery = ('question', '3D2826f6164707d214384e47eb616d4357'); 
    type.addQuery = ('value', current.variables.license_type); 
    type.query(); 
   
    if (type.next()) {
        var licprice = type.rec_misc; //get the price from the question value recurring price field
               current.price = licprice;
    }

})(current, previous);