Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

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

This is great! Thanks for the help.



But it's all showing bunched together.



Who requires assistance?: * Sarah Admin Muir Member Firm: NRFLLP Location: London Are you raising this request to Add or Remove access? : Add What is your access start date: 18/Nov/2017 13:45:51 NRF: true Are you raising this request for HR or Finance?: HR HR Action & HR Ad Hoc: true Which User Groups in the HR Action & HR Ad Hoc NRF Workflow do you need to add or remove access to? : EMEA HR Requestor



Is there a way to stop that and have them on each line? I'm not sure where I would put a new line in there.



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>


Hi Harish can you send the business rule for setting variable to  work notes ?

Hi Ahmed, check the post, the script is already their

Regards
Harish