- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 12:10 AM
I am trying to create a catalog and my requirement is to create 2 values in the catalog
1. a referencefield whose value will be from sys_alias table for which I have created 1 record in connection & credential alias and have provided an API key for the same
2. a lookup select field whose values will get populated onchange of the reference filed
I am trying to write a client script onchange of the first field and trying to make a rest api call in the script , but the challenge is how do I pass the api key from the first field so that I can authenticate the api and send the response .
I have tried the below option but they don't provide any useful info
alert(g_form.getDisplayValue('alias_selected'));
alert(g_form.getValue("alias_select"));
is there a way to achieve this or any other alternate that i can try
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 02:24 AM
@kiwi07 Okay Got it. Gliderecord to the API key table where they are stored and pass the alias name and return the API key
Example:
IF servicenow is alias
Key will be stored in below connection table
Gliderecord connection table with the name as Servicenow alias and return the API key
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 12:20 AM
Hello @kiwi07 ,
You can use the glideAjax in the client script pass the selected value from the Client script to Script include and make a call in SI and return the value to client script set the field value.
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user = g_form.getValue('reference field ');
//Call script include
var ga = new GlideAjax('global.sampleUtils'); //Scriptinclude
ga.addParam('sysparm_name', 'getUserDetails'); //Method
ga.addParam('userId',user); //Pass the value of reference field
ga.getXMLAnswer(getResponse);
function getResponse(response){
console.log(response);
var res = JSON.parse(response);
console.log(res);
g_form.setValue('aliasselect');
}
}
Script include:
var sampleUtils = Class.create();
sampleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAPIDetails: function(){
var userId = this.getParameter('userId');
//Call you rest API here and retutn the value
gs.addInfoMessage(obj+JSON.stringify(obj));
return JSON.stringify(obj);
},
type: 'sampleUtils'
});
This is just a sample script please modify according with your requirement and call Rest api in Script include part
Thanks,
Omkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 12:43 AM
@Omkar Kumbhar I am a bit confused with the answer in the first reference filed if alias is selected where do we get the API key from the alias to make the api call ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 12:50 AM
@kiwi07 Can you please clarify your question
Are you doing any integration with rest message to bring the API key and populate it on the form
OR
Are you just populating the field based on the Alias select field
Can you share the share shots it will be helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 01:06 AM - edited ‎01-23-2023 01:06 AM
@Omkar Kumbhar Below is the catalog I have, the first field is an alias field, I have created one alias "sample_alias", and when I select the alias I want to make a REST call onchange using the api key I have given in the alias while creation. Currently the data in the second field Building Name is static and i want to populate from the rest response , the challenge is that user can select any alias that he has created and the REST response is different for diffrent alias
For Example :-
Alias:- sample_alias
Build Name :- A,B,C
Alias:- sample_alias_new
Building Name:- 1,2,3