Populating MRVS using cartJS, optional field shows null

scorpion
Tera Contributor

I am trying to trigger/submit a catalog item (with MRVS) using cartJS. The mandatory fields are being populated correctly but the optional fields are being populated as "null". I would like to display it as Empty String.

I tried setting the variable as

source_nat': ''

 

but still it shows "null"

scorpion_0-1714749795375.png

 

I am using the code below.

var createRow = {
            'config_division': '' + division,
            'application_name': '' + appName,
            'source_nat': '',
            'm_application_name': '',
            'config_action': 'Add',
        };
mrvs.push(createRow);
var strMrvsData = JSON.stringify(mrvs);

 var cart = new sn_sc.CartJS();
    var item = {
        'sysparm_id': '687c8d571b196c98221b0fa5624bcb92',
        'sysparm_quantity': '1',
        'variables': {
            'requestor': '' + requestor,
            'connect_sr_firewallconfig': '' + strMrvsData    //MRVS
        }
    };

    var cartDetails = cart.addToCart(item);
    var checkoutInfo = cart.checkoutCart();

 

3 REPLIES 3

Sujatha V M
Kilo Patron
Kilo Patron

@scorpion  Please refer the below link for the similar method, 

 

https://www.servicenow.com/community/developer-forum/how-to-insert-the-value-into-mrvs-while-creatin...

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Hi @Sujatha V M 

 

Thanks for referring to the article but it doesn't solve the issue.
I have 10 variable in MRVS, only 3 of them are mandatory, rest 7 variables are optional. So when i am creating the MRVS I am not supplying values to those 7 optional Variables.

When i submit the Catalog using cartJS, those 7 variables shows up as "null", Which i don't want, Is there any way those variable values show up as an empty string (nothing) and not null on the form.

scorpion_0-1715014618325.png

 

@scorpion 

 

 

Can you please share some screenshots of the complete variables that shows "Null" values because in your screenshot, I can see two entries on the same column. 

 

Also, what's the variable type being used?

 

I tried the above script and it worked without any issues in my PDI. 

 

SujathaVM_0-1715066716692.png

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.