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

sreeram_nair
Tera Guru

Create a Catalog Client Script

You can create a Catalog Client Script (of type "onChange") to detect when the user selects an option and set the price on the RITM accordingly. The script will run when the user selects an option from the multiple-choice field.

Steps:

  1. Navigate to your Catalog Item in ServiceNow.
  2. Under Catalog Items, find the catalog item and open it.
  3. Go to Catalog Client Scripts (tab), and click New to create a new client script.
  4. Set the Type to onChange and select the multiple-choice variable as the Field.
  5. Use the following script to set the price based on the selected option:

Example Script:

(function executeRule(current, previous /*null when async*/) {
    // Get the selected value from the multiple choice variable
    var selectedLicense = g_form.getValue('your_multiple_choice_variable_name');

    // Create a mapping of options to Recurring Prices
    var priceMapping = {
        'License Type 1': 100, // Replace with actual license type and price
        'License Type 2': 200,
        'License Type 3': 300
    };

    // Set the price on the RITM
    var price = priceMapping[selectedLicense];
    if (price) {
        g_form.setValue('price_field_name', price); // Replace 'price_field_name' with the actual field name on the RITM
    }
})(current, previous);

 

 


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




ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ


ꜱʀᴇᴇʀᴀᴍ

@sreeram_nair 

Did you try running this code?

Are you sure this will work in client script?

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

Its just sample script. 


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




ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ


ꜱʀᴇᴇʀᴀᴍ

@sreeram_nair 

 

Thank you for the suggestion.  My preference is to pull it from the recurring price associated with the option selected.  That way, if I change the price on the variable option, it will automatically use the correct price and I don't have to remember to update a script or workflow or BR.