Storing Variable value in Script Include

shohebshaikh
Giga Expert

Hello Everyone,

I have created a catalog item with 5 variables: eg, first name, last name, contact, email, and company.

I want to store these values in a script include. How to achieve this?

Any leads will be appreciated.

Regards,
Shoheb

 

4 REPLIES 4

Aniket Sawant
Mega Expert

Hi,

You can use the following code.

for eg.

var fname = this.getParameter('sysparm_fname');
var lname = this.getParameter('sysparm_lname');

inside script include and in the client script you can write

var ga = new GlideAjax('script_include_name'); // SI Name
ga.addParam( 'sysparm_name', 'function_name'); // Function Name
ga.addParam('sysparm_first_name','variable_name');
ga.getXML(callback);

Please mark helpful or correct based on the impact.

Regards,
Aniket Sawant

Aniket Sawant
Mega Expert

Hi,

You have to use the catalog client script for accessing the variable as mentioned in the previous reply

and write a function such as the following script include.

getCI :function()
{
var arr = [];
var sysId =this.getParameter('sysparm_req_for');
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('assigned_to', sysId);
gr.query();
while(gr.next())
{
arr.push(gr.name.toString());
}
if(arr.length > 0)
return arr.toString();
else
return '';
},

 

Apeksha Joshi
Kilo Guru

Hi ,

you can achieve this with the help of catalog client script and script include .

catalog client script :

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var fname = g_form.getValue('first_name');

var lname = g_form.getValue('last_name');

var contact = g_form.getValue('contact');

var email = g_form.getValue('email');

var company = g_form.getValue('company');

var ga = new GlideAjax('SIname');

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

ga.addParam('sysparm_fname',fname);

ga.addParam('sysparm_lname',lname);

ga.addParam('sysparm_contact',contact);

ga.addParam('sysparm_email',email);

ga.addParam('sysparm_company',company);

ga.getxml(data);

function data(response)
{
var ans = reponse.responsexml.documentElement.getattribute("answer");

}

 

//Type appropriate comment here, and begin script below

}

script include :

SIfunction: function() {

var fname = this.getParameter('sysparm_fname');

var lname = this.getParameter('sysparm_lname');

var email = this.getParameter('sysparm_email');

var contact =this.getParameter('sysparm_contact');

var company = this.getParameter('sysparm_company');

}

If my reply helps you at all, I’d really appreciate it if you click the Helpful button and if my reply is the answer you were looking for, it would be awesome if you could click both the Helpful and Accepted Solution buttons!

 

Regards,

Apeksha

shohebshaikh
Giga Expert

Thanks for the help guys.

So I have created script include like below:

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

SIfunction: function(current) {

var fname = current.variables.first_name;
var lname = current.variables.last_name;
var email = current.variables.email;
var contact =current.variables.contact;
var company = current.variables.company;
var title = current.variables.title;
var bgrp = current.variables.blood_group;

},

type: 'UserCreation'
});