parameter passing in ui action

Jagadeesh_Maddi
Tera Contributor

hi folks,

I have some doubt regarding the  ui action. My requirement is to send parameters from client side script of ui action to the same server side script ui action (note: in list).Please Help in Understanding this!! 
I have used g_list.action("sys_id_ui_action","ui_action_name"), Along with triggering how to pass the parameters or utilize the parameters

4 REPLIES 4

Sanjay191
Kilo Patron

Hi @Jagadeesh_Maddi 

Please check the below article how we can run the server side code from the client callable ui action 

https://www.servicenow.com/community/itsm-articles/client-side-and-server-side-code-in-one-ui-action...

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You



Ankur Bawiskar
Tera Patron

@Jagadeesh_Maddi 

what's your actual business requirement?

what type of UI action is that? list or form?

share some details and screenshots

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

this was not a business requirement its just for knowledge purpose and doubt clarification.The ui action is on list view so without using script include can we just pass the parameters or use the parameters of client side script inthe server script just like other functions of same class like that 

Terry_Yeti
Giga Expert

I ran your question through snowcoder ai to help clarify the different ways to pass parameters in UI Actions—here's what you need to know:

*For Client-side UI Actions:*

If you need to pass parameters to a GlideAjax call:
javascript
function myUIAction() {
var ga = new GlideAjax('MyScriptInclude');
ga.addParam('sysparm_name', 'myFunction');
ga.addParam('sysparm_parameter1', g_form.getValue('field_name'));
ga.addParam('sysparm_parameter2', 'some_value');
ga.getXML(callback);
}

function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// Do something with the result
}


*For Server-side UI Actions:*

You can access form field values directly:
javascript
// Access current record fields
var incidentNumber = current.number;
var assignedTo = current.assigned_to;

// Pass to another function
myCustomFunction(incidentNumber, assignedTo);


*Passing parameters between UI Action and Script Include:*

Your Script Include needs to be client-callable:
javascript
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myFunction: function() {
var param1 = this.getParameter('sysparm_parameter1');
var param2 = this.getParameter('sysparm_parameter2');

// Your logic here
return result;
},
type: 'MyScriptInclude'
});


Could you share more details about what specific scenario you're working with? Are you trying to pass parameters to a Script Include, another record, or something else? That'll help me give you a more targeted solution.

_____________
I used snowcoder ai to generate this. If you need to tweak the requirements, you can run it through their Yeti AI for free.