The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing delivery time based on a variable in a catalog item

cfrazer
Giga Contributor

In my catalog items, I have a field that asks users when they need their item by. Is there a way to link that variable to the delivery time? For example, if they said they needed it on November 17th (14 days from now), is there a way to have the delivery time show 14 days as well so that it matches their response? Or, is there a way to make the workflow recognize their response and match the due date to that? Would any of this be possible?

3 REPLIES 3

kristenankeny
Tera Guru

You can create a business rule on the sc_req_item table, before insert, to set the due date based on your variable.


Since due date is a date/time I believe and our forms only collect date, and we have a couple different variables that could drive the due date, we script it like this:



var reqdate = '';



if(current.variables.requested_by_date){


reqdate = current.variables.requested_by_date.getDisplayValue() + ' 16:00:00';


}


else if(current.variables.business_critical_date){


reqdate = current.variables.business_critical_date.getDisplayValue() + ' 16:00:00';


}


else if(current.variables.requested_completion_date){


reqdate = current.variables.requested_completion_date.getDisplayValue() + ' 16:00:00';


}



var gDate = new GlideDateTime();


gDate.setValue(reqdate);


current.due_date.setValue(gDate);


Deepak Kumar5
Kilo Sage

Create a Variable "Delivery Time" and update it's value based on need their item by.



var date1 = new Date(g_form.getValue('need their item by'));  


var date2 = new Date();  


var timeDiff = Math.abs(date2.getTime() - date1.getTime());  


var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));


var del_date = diffDays +" Days"


g_form.setValue('Delivery_Time',del_date )



now in workflow run script set your due date to 'need their item by' .


current.due_date = current.variables.need their item by;