How to pull field values in tabular format in service catalog

reddy8055
Tera Contributor

Hi,

I have catalog form with Requested for field (reference to sys_user table), this field auto populates based on user logged info. We have custom table with 4 fields (email, course name, completed date,  Name). I want to pull all 4 fields in tabular format on catalog form based on requested for email. How can I do this?

Thanks,

4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

hello @reddy8055 ,

If you expecting to auto populate those data in a tabular format it might be bit complicated because you might have to write some custom widget code and place that widget on the catalog item using custom type variable which involves coding .

 

Instead of that you can create four fields and auto populate them using on change client script and script include 

 

Hope this helps 

MARK MY ANSWER CORRECT IF THIS HELPS YOU 

Hi Mohit,

There are multiple records with same email, so want to pull dynamically as a tabular format.

 

I have created catalog client script but its not working. I am able to receive the alert correctly but table is not created.

 

function onChange(control, oldValue, newValue, isLoading) {


if (isLoading || newValue == '') {


return;


}


document.getElementById("test").style.visibility = "visible";


//Type appropriate comment here, and begin script below


var a = g_form.getValue('requested_for');


var b = g_form.getReference('requested_for').email;


alert(b);


var ga = new GlideAjax('GroupChange');


ga.addParam('sysparm_name', 'groupchng');


ga.addParam('sysparm_email', b);


ga.getXML(getgrp);


function getgrp(response)


{


var answer = response.responseXML.documentElement.getAttribute("answer");


alert(answer);


var people = answer.split(',');


var row = document.getElementById("test");


for (i = 1; i < people.length; i++)


{


//document.getElementById("gp").innerHTML=b;

 

var ab = "gm" + i;


var bc = "gp" + i;


var g = document.createElement('tr');


row.appendChild(g);


var g1 = document.createElement('td');


g1.setAttribute("id", bc);


g.appendChild(g1);

 

var g2 = document.createElement('td');


g2.setAttribute("id", ab);


g.appendChild(g2);

 

//document.getElementById("gm").id = "gm"+i;


document.getElementById(bc).innerHTML = b;


document.getElementById(bc).style.border = "1px solid black";


document.getElementById(ab).innerHTML = people[i];


document.getElementById(ab).style.border = "1px solid black";


}


}


}

 

Thanks

@reddy8055 then i can suggest you one thing try creating MVRS which is called as multi row variable set which will be in a tabular format .

Once you select your user you can auto populate MVRS with the data .

In MVRS you can create these four fields .

And MVRS can take multiple records 

 

Example : refer this article it shows how to auto. populate multiple records in MVRS based on a field selection in catalog item 

 

https://www.servicenow.com/community/developer-articles/how-to-add-rows-dynamically-in-multi-row-var...

 

Hope this helps 

If it helped you mark the answer correct 

 

I tried the above link, still not working.

 

script include:

var PopulateVTAValues = Class.create();
PopulateVTAValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {

listcollector: function() {

var listValuename = [];
var email = this.getParameter('sysparm_email');
//var query = 'sys_idIN' + userInfo;
if (userInfo) {
var gr = new GlideRecord('u_vta');
gr.addEncodedQuery('u_email_id', email);
gr.query();
if (gr.next()) {

listValuename.push({
// "name": gr.getValue('u_course_name'),
// "email": gr.getValue('u_email_id')
"name": gr.u_course_name,
"email": gr.u_email_id
});
}
}
// gs.info('ARB JSON'+JSON.stringify(listValuename));
gs.log(" ***CKR org: " + listValuename);
return JSON.stringify(listValuename);
},

type: 'PopulateVTAValues'
});