Populate Short Description for Catalog Items with Form Variable Value.

JayGervais
Kilo Sage

Hi there, 

We have a catalog item and all records being created contain a generic title (short_description) that was originally added when the item was created. This is problematic because in our list view it has become impossible to easily navigate through the requests. The form to create a request includes form variables including a field for 'What are you requesting? (what_are_you_requestion)' that displays information on the request details page. I have been trying to create a script to populate the Short Description with this variable but have not been able to make it work.

The are some of the things I have tried...

Within the workflow, I added a script to the Activity Properties: Catalog Task:

task.short_description = current.variables.what_are_you_requesting;

I also tried adding a Run Script with the following:

var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', current.cat_item);
gr.query();
if (gr.next()) {
	gr.short_description = current.variables.what_are_you_requesting;
	gr.update();
}

My last attempt was to create a Business Rule. I tried both async and before insert/update hoping new records could include a title. I have tried a few script variations but this is my most recent:

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

	// Add your code here
	if (current.name == 'Generic IT Request') {
		current.short_description = current.variables.what_are_you_requesting;
	}

})(current, previous);

I have been struggling to come up with a solution for this and appreciate any advice. Cheers!

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

I'm trying to understand WHAT record...are you trying to change the short description? Because some of your attempts look like you're trying to change the task short description...then others...it's the RITM short description.

If you're trying to change the RITM short description...and this workflow runs on the RITM table...then you should be able to easily change the short description using something like this in a run script activity:

current.short_description = current.variables.what_are_you_requesting.toString();

But all of this is assuming that 1) you're running this workflow on the RITM table and 2) The name of your variables...is correct...so check that.

find_real_file.png

find_real_file.png

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

8 REPLIES 8

dvp
Mega Sage
Mega Sage

To set the short description on catalog task use

task.short_description = current.request_item.variables.what_are_you_requesting;

SanjivMeher
Kilo Patron
Kilo Patron

If you are talking about setting title for a requested item, you need a run script or onBefore Insert Business rule with below script

 

for ex

if (current.cat_item.name == 'Generic IT Request') {

current.short_description = current.short_description+'-'+current.variables.what_are_you_requesting;

}

 

If you also want to set short description in request, add a run script in the requested item workflow, for ex

 

if (current.cat_item.name == 'Generic IT Request') {

var req = new GlideRecord(sc_request);

req.get(current.request);

req.short_description = req.short_description+'-'+current.variables.what_are_you_requesting;

}

 

If you want to set it in the task short description, you can do following in Catalog task activity

 

task.short_description = '<Task to be performed>'+current.variables.what_are_you_requesting;


Please mark this response as correct or helpful if it assisted you with your question.

Thank you for the insight. I was able to achieve what I was trying to do with a close variation of what you suggested for the tasks.

task.short_description = 'Generic IT Request (Reassign): ' + current.variables.what_are_you_requesting.toString();

JayGervais
Kilo Sage

For anyone interested, this is my working code to add the string from the variable to the short_description of both the catalog item and task.

var reqDesc = 'IT Request: ' + current.variables.what_are_you_requesting.toString();
if (reqDesc.length > 50) {
	var trimReqDesc = reqDesc.substring(0, 50);
	var finReqDesc = trimReqDesc.trim() + '...';
} else {
	finReqDesc = reqDesc;
}

current.short_description = finReqDesc;
task.short_description = finReqDesc;
task.description = current.variables.what_are_you_requesting.toString();