Set due date on catalog item depending on variable selection and calculating from submission date

MonicaW
Tera Guru

Hello:

I have searched the Community for this and haven't been able to find quite what I'm looking for.  I need to create a catalog item workflow script to set the due date of the item based on the date it was requested.  If they select Project from the multiple choice question, I need it to set to 180 business days.  If they select Support, I need it to set to 30 business days.  Can anyone help me with the script I would need?  (I'm not well versed at writing them yet.)

Multiple Choice variable: proj_support

Values: proj or support

Thank you for any assistance.

Monica Webster

 

1 ACCEPTED SOLUTION

MonicaW
Tera Guru

I figured this out - used the following:

if (current.variables.proj_support == 'support'){

var gdt = current.due_date.getGlideObject();

gdt.addDays(30);

current.due_date = gdt;

// Populate the Due Date on the REQ

var grREQ = new GlideRecord('sc_request');

grREQ.addQuery('sys_id', current.request);

grREQ.query();

if(grREQ.next())

 {

  grREQ.due_date = current.due_date;

  //grREQ.description = current.variables.u_purchase_reason;

  grREQ.update();

 }

}

View solution in original post

5 REPLIES 5

Ct111
Giga Sage
Hi , Fetch the value of that field like below var field = current.variables.fieldnm; if(field == ‘Support’) { Add the code as mentioned in below link https://community.servicenow.com/community?id=community_question&sys_id=8b48cbaddb1cdbc01dcaf3231f961928 } Mark my answer as correct and helpful if it helped

MonicaW
Tera Guru

Here's what I tried but it's not working.  Apologies, I'm not a scripter...

 

{
var field = current.variables.proj_support;
if(field == 'Project')

var tz = gs.getSession().getTimeZone();

var gdt = new GlideDateTime(gs.nowDateTime());

gdt.setTZ(tz);

task.start_date = gdt;


var ed = new GlideDateTime(gdt);

ed.addDays(180);

task.end_date = ed;
}

MonicaW
Tera Guru

Attaching the error that shows in the workflow.

MonicaW
Tera Guru

Can anyone suggest what I should try?  Thank you.