Putting Catalog Item Variables in a Mail Script

alexcharleswort
Tera Expert

Hello all!

What I am ultimately trying to do is utilize the Approval User functionality in the workflow. The issue that I am having is that I can't get the specific variables I want to appear on the approval email. The variables that I want to appear in the email are: tra_staff_name, tra_emp_id and tra_manager.

I imagine that the best way to do this is to create a unique notification to tie to the approval in the workflow and that I will need to use a custom mail script. I have tried many different renditions and other community posts and haven't quite gotten what I wanted out of them. I do not want to list every variable on the item and it would be idea to have them in a nice format such as:

Staff Name: XXXXX

Emp ID: XXXXX

Manager: XXXXX

So how do I properly get my specific variables in a mail script and format it so that it looks nice to the user and not a jumbled mess?

Any help would be greatly appreciated!

Thanks!!

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use this in the email script



var set = new GlideappVariablePoolQuestionSet();      


set.setRequestID(current.sysapproval);


set.load();


var vs = set.getFlatQuestions();


for (var i=0; i < vs.size(); i++) {


      if(vs.get(i).getName()=='tra_staff_name' || vs.get(i).getName()=='tra_emp_id' ||vs.get(i).getName()=='tra_manager' ) {


            template.print('         ' +   vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + "\n");  


      }


}


View solution in original post

5 REPLIES 5

Abhinay Erra
Giga Sage

Use this in the email script



var set = new GlideappVariablePoolQuestionSet();      


set.setRequestID(current.sysapproval);


set.load();


var vs = set.getFlatQuestions();


for (var i=0; i < vs.size(); i++) {


      if(vs.get(i).getName()=='tra_staff_name' || vs.get(i).getName()=='tra_emp_id' ||vs.get(i).getName()=='tra_manager' ) {


            template.print('         ' +   vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + "\n");  


      }


}


Awesome!! I just tweaked it a tad bit to give it a better format. I ended up changing '\n' to '<br>' and it worked wonderfully!



Thank you! I want to test one more thing before I close this discussion out.


Hello Abhinay,



How would you make it so that if you had more than one variable set being written that it displays the sections with a space in between them? There will always be a "employee information" variable set that has all the details on who the user is and where they are from. Then we will need to make it easy for the approver to see what is being approved.   I am using the method you described and it lumps the variable sets together.



Example (how it currently displays)


Employee Information:
        Requestor Name = System Administrator
        What is the Employees Name? = Angelo Tadros
        What is the Employee's Department = Finance
        Employee's Location = 5310 1st Avenue North, Birmingham,AL
        Effective Date = 03/22/2017 07:24:00 EDT
        Other Comments =
        What type of Access Request is it? = Add
        Financial Services = true
        Inventory = false
        General Ledger = true
        E-Commerce = false
        Sales = false
        Facilities Management = true
        Service = true
        Other Comments =





How I would like it to display


Employee Information:   //1st variable set
        Requestor Name = System Administrator
        What is the Employees Name? = Angelo Tadros
        What is the Employee's Department = Finance
        Employee's Location = 5310 1st Avenue North, Birmingham,AL
        Effective Date = 03/22/2017 07:24:00 EDT
        Other Comments =
        What type of Access Request is it? = Add



Access being Requested:   //2nd variable set
        Financial Services = true
        Inventory = false
        General Ledger = true
        E-Commerce = false
        Sales = false
        Facilities Management = true
        Service = true
        Other Comments =





Abhinay Erra
Giga Sage

If I have answered your question, Please mark my response as correct so that it gets removed form unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button. You need to open the thread directly and you will see a correct answer button with red star.     Please review this How To Mark Answers Correct From Community Inbox