copy variables to work-notes

SMuir
Mega Guru

I have a script that seems to be working fine, but I need to tidy it up a bit.

For the moment the business rule copied the variables on the requested item to the comments [work-notes]

But as you can see its not very tidy. Is   there a way to get only the variables the customer selected to show rather than all the variables on the form?

Variables:

Who requires assistance?: Mitch Sharpe

Member Firm: NRFLLP

Location: London

Are you raising this request to Add or Remove access? : Add

What is your access start date: 15/Nov/2017 11:05:34

What is your access end date?:

What is your access end date?:

NRF: false

GSC: true

Are you raising this request for HR or Finance?: Finance

HR Action & HR Ad Hoc: false

Adhoc Finance Requests for GSC: false

Fixed Asset Registration: true

Time Amendment: false

Vendor Requests: false

Which User Groups in the Adhoc Finance Requests for GSC Workflow do you need to add or remove access to?:

Which User Groups in the Adhoc Finance Requests for GSC Workflow do you need to add or remove access to?:

Which User Groups in the Fixed Asset Registration for NRF Workflow do you need to add or remove access to? :

Which User Groups in the Fixed Asset Registration for GSC Workflow do you need to add or remove access to? : EMEA_PTP_FA_TECHNICIAN

Which User Groups in the HR Action & HR Ad Hoc NRF Workflow do you need to add or remove access to? :

Which User Groups in the HR Action & HR Ad Hoc GSC Workflow do you need to add or remove access to? :

Which User Groups in the Time Amendment GSC Workflow do you need to add or remove access to? :

Which User Groups in the Time Amendment NRF Workflow do you need to add or remove access to? :

Which User Groups in the Vendor Requests NRF Workflow do you need to add or remove access to? :

Which User Groups in the Vendor Requests GSC Workflow do you need to add or remove access to? :

If you have any additional comments or information, please fill them in here.:

Current script is

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

// Add your code here.

var wn = 'Variables:';

for (key in current.variables) {

var v = current.variables[key];

wn += '\n' + v.getGlideObject().getQuestion().getLabel() + ': ' + v.getDisplayValue();

}

current.comments = wn;

})(current, previous);

Kind regards

Sarah

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Try the below code. I am setting it to description. It pulls only filled variables



toDescription();


function toDescription() {


  var notEmptyVars = [];


  var v;


  var desc = '';


  /* Put all variable values and labels from the variable pool into an array */


  for (var i in current.variables) {


      v = current.variables[i];


      /* Only include non-empty variables, and exclude Label and Container variables */


      if (v != '' && v != 'false' && v.getGlideObject().getQuestion().type != 11 && v.getGlideObject().getQuestion().type != 19 && v.getGlideObject().getQuestion().type != 20) {


          desc += v.getGlideObject().getQuestion().getLabel() + ': ' + v.getDisplayValue() + '\n';


      }


  }


  current.description = desc;


}


Regards
Harish

View solution in original post

16 REPLIES 16

Harish KM
Kilo Patron
Kilo Patron

It does come in order for me in worknottes


Regards
Harish

Yes, I am happy the variables are showing in order, the problem is they aren't on a new line, Showing bunched in a paragraph,



If there a way to get each variable on a new line?



Sarah Muir | IT ServiceNow Technician



Norton Rose Fulbright LLP


3 More London Riverside, London, SE1 2AQ, United Kingdom


Tel +44 20 7444 3835 | Mob +44 7738 808219 | Fax +44 20 7283 6500


sarah.muir@nortonrosefulbright.com


NORTON ROSE FULBRIGHT


Law around the world


nortonrosefulbright.com<http://www.nortonrosefulbright.com>



Norton Rose Fulbright and Chadbourne & Parke have joined forces, giving our clients access to more than 4,000 lawyers worldwide.


nortonrosefulbright.com/chadbourne<http://www.nortonrosefulbright.com/chadbourne>


Harish KM
Kilo Patron
Kilo Patron

I am getting it into a new line.



find_real_file.png


Regards
Harish

This is the Business rule






When I test and a Catalog item



This is what I get






Sarah Muir | IT ServiceNow Technician



Norton Rose Fulbright LLP


3 More London Riverside, London, SE1 2AQ, United Kingdom


Tel +44 20 7444 3835 | Mob +44 7738 808219 | Fax +44 20 7283 6500


sarah.muir@nortonrosefulbright.com


NORTON ROSE FULBRIGHT


Law around the world


nortonrosefulbright.com<http://www.nortonrosefulbright.com>



Norton Rose Fulbright and Chadbourne & Parke have joined forces, giving our clients access to more than 4,000 lawyers worldwide.


nortonrosefulbright.com/chadbourne<http://www.nortonrosefulbright.com/chadbourne>


Harish KM
Kilo Patron
Kilo Patron

check your code. Even i hav written BR


Regards
Harish