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

No worries, glad you got it working. I've also replied to your other post. Take a look and let me know if you have any questions.

Casey Bates
Kilo Contributor

If I have a universal workflow and I wanted to adapt this to catalog items using that workflow, could I complete this same objective? Would this be done using the variables or Catalog Client scripts or Catalog UI policies using a script?

If not, modifying or creating a workflow for every catalog item is not sustainable. 

Today our universal workflow fits most catalog items by doing the following:

  1. Begin
  2. Tasks | Catalog Task: Task 1
    1. Script:
      short_description = current.variables.taskshortdescription;
      task.description = current.variables.taskdescription;
      task.assignment_group = current.variables.agroup;
  3. Conditions | If: Is there a second activity?
    1. Script:
      answer = ifScript();
      function ifScript() {
      if (current.variables.secondtask == 'Yes') {
      return 'yes';
      }
      return 'no';
      }
      1. No -> End
      2. Yes
        1. Tasks | Catalog Task: Task 2
          1. Script:
            short_description = current.variables.taskshortdescription2;
            task.description = current.variables.taskdescription2;
            task.assignment_group = current.variables.agroup2;
        2. Conditions | If: Is there a third activity?
          1. Script:
            answer = ifScript();
            function ifScript() {
            if (current.variables.secondtask == 'Yes') {
            return 'yes';
            }
            return 'no';
            }
            1. No -> End
            2. Yes
              1. Tasks | Catalog Task: Task 3
                1. Script:
                  short_description = current.variables.taskshortdescription3;
                  task.description = current.variables.taskdescription3;
                  task.assignment_group = current.variables.agroup3;

Casey Bates
Kilo Contributor

Wow that is much uglier than i typed it lol. 

Casey Bates
Kilo Contributor

If I have a universal workflow and I wanted to adapt this to catalog items using that workflow, could I complete this same objective? Would this be done using the variables or Catalog Client scripts or Catalog UI policies using a script?

If not, modifying or creating a workflow for every catalog item is not sustainable. 

Today our universal workflow fits most catalog items by doing the following:

  1. Begin
  2. Tasks | Catalog Task: Task 1
    1. Script:
      short_description = current.variables.taskshortdescription;
      task.description = current.variables.taskdescription;
      task.assignment_group = current.variables.agroup;
  3. Conditions | If: Is there a second activity?
    1. Script:
      answer = ifScript();
      function ifScript() {
      if (current.variables.secondtask == 'Yes') {
      return 'yes';
      }
      return 'no';
      }
      1. No -> End
      2. Yes
        1. Tasks | Catalog Task: Task 2
          1. Script:
            short_description = current.variables.taskshortdescription2;
            task.description = current.variables.taskdescription2;
            task.assignment_group = current.variables.agroup2;
  4. Conditions | If: Is there a third activity?
    1. Script:
      answer = ifScript();
      function ifScript() {
      if (current.variables.secondtask == 'Yes') {
      return 'yes';
      }
      return 'no';
      }
      1. No -> End
      2. Yes
        1. Tasks | Catalog Task: Task 3
          1. Script:
            short_description = current.variables.taskshortdescription3;
            task.description = current.variables.taskdescription3;
            task.assignment_group = current.variables.agroup3;

Casey Bates
Kilo Contributor

If I have a universal workflow and I wanted to adapt this to catalog items using that workflow, could I complete this same objective? Would this be done using the variables or Catalog Client scripts or Catalog UI policies using a script?

If not, modifying or creating a workflow for every catalog item is not sustainable. 

Today our universal workflow fits most catalog items by doing the following:

  1. Begin
  2. Tasks | Catalog Task: Task 1
    1. Script:
      short_description = current.variables.taskshortdescription;
      task.description = current.variables.taskdescription;
      task.assignment_group = current.variables.agroup;
  3. Conditions | If: Is there a second activity?
    1. Script:
      answer = ifScript();
      function ifScript() {
      if (current.variables.secondtask == 'Yes') {
      return 'yes';
      }
      return 'no';
      }
      1. No -> End
      2. Yes
        1. Tasks | Catalog Task: Task 2
          1. Script:
            short_description = current.variables.taskshortdescription2;
            task.description = current.variables.taskdescription2;
            task.assignment_group = current.variables.agroup2;
  4. Conditions | If: Is there a third activity?
    1. Script:
      answer = ifScript();
      function ifScript() {
      if (current.variables.secondtask == 'Yes') {
      return 'yes';
      }
      return 'no';
      }
      1. No -> End
      2. Yes
        1. Tasks | Catalog Task: Task 3
          1. Script:
            short_description = current.variables.taskshortdescription3;
            task.description = current.variables.taskdescription3;
            task.assignment_group = current.variables.agroup3;