Auto Populate incident details on a multi row variable set on a catalog item

Community Alums
Not applicable

Hi Team,

 

I have a scenario where I want to auto populate list of incident records on multi row variable set that i have created on a catalog item,and i want to do it on load of the catalog item.

 

 

below are the details of it.

 

multi row variable set variable name: incident_details

var1 name:incident_short_description

var2 name:incident_description

 

var1 will have the short description of incident records

var2 will have description of incident records.

 

i want only the active incident details.

 

Request you to help on this requirement.

 

Thanks and regards

Nasheet Khan

 

1 ACCEPTED SOLUTION

try this out

Client callable Script Inlcude

var CatalogpostSol = Class.create();
CatalogpostSol.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	getIncidetns:function(){
		var res = [];
		var incGr = new GlideRecord('incident');
		incGr.addEncodedQuery('ORDERBYDESCsys_created_on'); // replace the encodedquery if needed
		incGr.setLimit(5);
		incGr.query();
		while(incGr.next()){
			var shortD = incGr.getValue('short_description');
			var desc = incGr.getValue('description');
			var tempObj = {};
			tempObj.add_row_onload_to_multi_row_variable_set /*the variable name maps to SD*/ = shortD?shortD:'';
			tempObj.column2  /*the variable name maps to description*/= desc?desc:''; 
			res.push(tempObj);
		}
		return JSON.stringify(res);
	},
    type: 'CatalogpostSol'
});

OnLoad Catalog Client Script

function onLoad() {
   //Type appropriate comment here, and begin script below
   var ga = new GlideAjax('CatalogpostSol');
   ga.addParam('sysparm_name','getIncidetns');
   ga.getXMLAnswer(function(ans){
	g_form.setValue('catalogpostsol'/*interName of the variable set*/,ans);
   });

}

 

Regards,
Chaitanya

View solution in original post

6 REPLIES 6

OlaN
Giga Sage
Giga Sage

Hi,

Your question/scenario is hard to understand. Please elaborate. Also describe what the use case is.
And if possible add images to show how you mean.

Community Alums
Not applicable

Hi OlaN,
I have created a catalog item with multi row variable as variable with two columns.You can have a look at the below snapshot of the same.

 

nasheetkhan_0-1733121036853.png


Currently I am using the below script to populate the above values in the two columns when the catalog items is loaded.

Script:
------

function onLoad() {

    var rowObj = [];
    rowObj.push({
        "actions": "",
        "add_row_onload_to_multi_row_variable_set": "Does this work?",
        "column2": "papa mere dost hain"
    }, {
        "actions": "",
        "add_row_onload_to_multi_row_variable_set": "It worked",
        "column2": "Mummy meri dost"

    });

    g_form.setValue('mrv', JSON.stringify(rowObj));

}

My Requiremnet :
Now i want the data to be pulled from incident table and not hard coded as it is done in the script above.
I want from incident table short description and description.

Note:If you are not able to open the snapshot attached above you can have look at the attachment.

Thanks and regards
Nasheet Khan
+919955860495


 

Chaitanya ILCR
Kilo Patron

Hi @Community Alums ,

How do you know from which incident the short description and description should be pulled?
Do you have a UI action or something on the Incident table which opens the catalog form?

 

Regards,

Chaitanya

Community Alums
Not applicable

Hi Chaitanya,

I want to populate first five record's description and short description to be populate once the form is opened by end user.
Just open the catalog item either in service portal or in the platform view it simply populates the first 5 records description and short description.

Thanks and regards

Nasheet Khan

+919955860495