Auto-populate field

Becky Barton
Kilo Contributor

Hi,

I'm looking for some help in auto-populating a field in a request. I have created a catalog item which includes a single line text box for users to enter a project code. I am looking for the data from this field to automatically populate the project code in the request Item the form will create.

From my research, I think this will have to be done via a business rule on the request item table and then with scripting to pull the information for the catalog item.  can anybody advise me?

( i have very little experience with coding so a step by step would be greatly approciated.

Many Thanks

Becky

 

1 ACCEPTED SOLUTION

Waleska
Kilo Guru

It would be a business rule, you would do the following:

Create a new business rule and select the "Advanced" option.

Under When to run, choose Before and then check mark Insert (you can also checkmark update if there is a chance that it will be updated after submission).

In the Advanced tab, you will want to put something like this:

if(current.variables.variable_name){
current.project_code = current.variables.variable_name;
}

 

View solution in original post

2 REPLIES 2

Jyoti8
Kilo Guru
Hi Becky Barton,
 
I have used in catalog client script and Script include As below :
I hope it will help you.

Catalog Client Script 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var a = g_form.getValue('select_user');
var b = new GlideAjax('user_location');/

b.addParam('sysparm_name','loc');
b.addParam('sysparm_loc1',a);/
b.getXML(userdatapopulate);

function userdatapopulate(response)
{

var answer=response.responseXML.documentElement.getAttribute("answer");
//var returneddata=answer;
g_form.setValue('user_location', answer);
}

//Type appropriate comment here, and begin script below

}

 

Script include :

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

loc: function(){
var l = this.getParameter('sysparm_loc1');
//gs.addInfoMessage(unm);
var location = new GlideRecord('sys_user');
location.addQuery('sys_id',l);
location.query();
if(location.next())
{
//gs.addInfoMessage(user.email);
return location.location;
}

} ,

type: 'user_location'
});

 

 

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..:)

Thanks

Waleska
Kilo Guru

It would be a business rule, you would do the following:

Create a new business rule and select the "Advanced" option.

Under When to run, choose Before and then check mark Insert (you can also checkmark update if there is a chance that it will be updated after submission).

In the Advanced tab, you will want to put something like this:

if(current.variables.variable_name){
current.project_code = current.variables.variable_name;
}