How do I create a variable that's default value is text and value of another variable?

Casey Bates
Kilo Contributor

Hey Community!

This is what I am looking to do and would like some guidance:
REQ and RITM titles to equal the value selected from multiple variables on the catalog item plus some text. Lastly, the SCTASKS to equal a value from each variable. I have a sweet example to explain. 

Variable1:

Type: Select Box

Question: Do you want a chocolate or vanilla cake?

Name: Flavor

Choices: Chocolate, Vanilla

 

Variable2:

Type: Select Box

Question: Do you want buttercream or whipped icing?

NameType

Choices: Buttercream, Whipped

 

I want the title of the REQ and RITM to be:

Bake a (flavor) cake with (Type) icing

I want the title of the SCTASKS to be:

Bake a (flavor) cake

Make and finish with (Type) icing

 

So I assume the variable (Title_REQ, Title_RITM, Title_SCTASK) are Single line text (types) and setting the Default value will consist of some js. 

Cheers and thanks in advance.

find_real_file.png

 

 

 

1 ACCEPTED SOLUTION

Brent Sutton
Mega Sage

Hi Casey,

You can achieve this in your item’s workflow. Setup a new workflow on the sc_req_item table and associate it with your catalogue item. The end result will look something like this:

find_real_file.png

 Your workflow will consist of two activities. The first activity will be a run script which will set the short description (I have assumed that this is the title you are referring to) for both the RITM and REQ.

Run Script Activity:

var sd = gs.getMessage("Bake a {0} cake with {1} icing",[current.variables.flavor.getDisplayValue(), current.variables.type.getDisplayValue()]);

current.short_description = sd;
var req = new GlideRecord("sc_request");

if (req.get(current.request)) {
	req.setValue("short_description", sd);
	req.update();
}

find_real_file.png

The second step will be a catalog task activity. The key here is to tick the Advanced option in the Script section. In here we will place the following code:

task.short_description = gs.getMessage("Bake a {0} cake. Make and finish with {1} icing",[current.variables.flavor.getDisplayValue(), current.variables.type.getDisplayValue()]);

find_real_file.png

Now all your short descriptions should contain your personalised text. The code assumes that both of your fields (flavor and type) are mandatory and will always contain values. If they are not mandatory then you will need to add some checks to ensure you cater for when no value has been provided.

find_real_file.png

Let me know if this worked for you. Tested fine in my London developer instance.

Brent

P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.

View solution in original post

12 REPLIES 12

Casey Bates
Kilo Contributor

This continues for as many tasks are needed. 

Casey Bates
Kilo Contributor

Image in case it is easier for you with the font changes. 

 

find_real_file.png

Hi Casey,

In this scenario, you probably don't want to be messing with your universal workflow to accommodate a small number of catalog items that need this logic applied.

I would probably create a business rule to do the work and set it to only execute only for the items that need this logic applied.

Brent