How to generate variable value based on requested_for value

Deepa12
Tera Contributor

I have requirement - create a variable Account name with the type single line text.

Account name should generate depands on requested for value(the value coming from order confirmation page, by default requested for value displays currently logged in user name but end user can select different username. account name should generate based on requested for value).

Deepa12_0-1726838356338.png

 

 

* Account name value generated with the below conditions:

When variable category = A and variable location =  abc

generate the account name - xadmin+requested for user id

When variable category = B and variable location = xyz

generate the account name = tuser+requested for user id

 

Pls assist me, 

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hello @Deepa12 

You can achieve this requirement using before insert BR on your specific catalog item.
I will place the screenshots below, please update as per your scenario:

MurthyCh_0-1727029022968.png

CODE:

(function executeRule(current, previous /*null when async*/ ) {

    if (current.variables.category == 'a' && current.variables.location.city == 'Baltimore') { //replace with your location and category values
        current.variables.account_name = 'x-admin' + current.requested_for.user_name;
    } else if (current.variables.category == 'b' && current.variables.location.city == 'Lakewood') { //replace with your location and category values
        current.variables.account_name = 'tuser' + current.requested_for.user_name;
    }

})(current, previous);

NOTE: Make sure to give your variable names and fields correctly.

AccoutName.gif

 Hope it helps:)

Thanks,
Murthy

View solution in original post

1 REPLY 1

Murthy Ch
Giga Sage

Hello @Deepa12 

You can achieve this requirement using before insert BR on your specific catalog item.
I will place the screenshots below, please update as per your scenario:

MurthyCh_0-1727029022968.png

CODE:

(function executeRule(current, previous /*null when async*/ ) {

    if (current.variables.category == 'a' && current.variables.location.city == 'Baltimore') { //replace with your location and category values
        current.variables.account_name = 'x-admin' + current.requested_for.user_name;
    } else if (current.variables.category == 'b' && current.variables.location.city == 'Lakewood') { //replace with your location and category values
        current.variables.account_name = 'tuser' + current.requested_for.user_name;
    }

})(current, previous);

NOTE: Make sure to give your variable names and fields correctly.

AccoutName.gif

 Hope it helps:)

Thanks,
Murthy