How to use the delivery time on sc_cat_item instead of the one defined on the workflow?

Mathias9
Kilo Contributor

Hi guys,

Note: I'm the new guy, trying to learn some ServiceNow development 🙂 

I'm trying to figure out how, to use the already presented delivery time on sc_cat_item to define the delivery time shown on the service portal. I have figured out that the delivery time shown on the service portal comes from the workflow properties, the item uses.

The thing is, we / my company have hundreds of items using the same workflow, and i would really like to differentiate between the delivery time of these.

How can that be done?  

find_real_file.png

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

You could could clone the SC Catalog Item Widget and modify it to include some code like this near the end of the Server Side script: 

	var cat_item = new GlideRecord('sc_cat_item');
	cat_item.get($sp.getParameter("sys_id"));
	if(cat_item.getDisplayValue('delivery_time')) {
		data.sc_cat_item.estimated_delivery_time = cat_item.getDisplayValue('delivery_time');
	}

In mine I put it right above the closing })()

Assuming you don't want to modify the out of the box pages (which I would strongly advise against)...

You would then clone the sc_cat_item page and replace the SC Catalog Item widget with your modified one. 

You'd need a Page Route Map to direct from sc_cat_item to your new page.

Otherwise, just replace the SC Catalog Item widget on the sc_cat_item page with your modified one

Basically this code would check to see if you have set a value on delivery_date on the item itself and display that value in the portal, otherwise it will use the calculated value based on the workflow that is set. 

find_real_file.pngfind_real_file.png

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

4 REPLIES 4

Michael Fry1
Kilo Patron

Switch to a FLOW, build a new Action that calculates the delivery date based on the delivery time set in that field. Have it populate on the RITM so it shows on portal for end user.

Michael Jones -
Giga Sage

You could could clone the SC Catalog Item Widget and modify it to include some code like this near the end of the Server Side script: 

	var cat_item = new GlideRecord('sc_cat_item');
	cat_item.get($sp.getParameter("sys_id"));
	if(cat_item.getDisplayValue('delivery_time')) {
		data.sc_cat_item.estimated_delivery_time = cat_item.getDisplayValue('delivery_time');
	}

In mine I put it right above the closing })()

Assuming you don't want to modify the out of the box pages (which I would strongly advise against)...

You would then clone the sc_cat_item page and replace the SC Catalog Item widget with your modified one. 

You'd need a Page Route Map to direct from sc_cat_item to your new page.

Otherwise, just replace the SC Catalog Item widget on the sc_cat_item page with your modified one

Basically this code would check to see if you have set a value on delivery_date on the item itself and display that value in the portal, otherwise it will use the calculated value based on the workflow that is set. 

find_real_file.pngfind_real_file.png

Hope this helps!

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Thanks, worked like a charm!

kirankumar_
Tera Contributor

Hello @Michael Jones ,

 

I'm getting the below error,

Server JavaScript error Cannot set property "estimated_delivery_time" of undefined to "2 Days"

 

Could you please suggest on this.

 

Thanks,

Kiran