
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2023 03:58 AM
Hello Guys,
My use case is to copy the child tickets work notes to parent ticket on click of Custom UX Modal button
For that I'm using api.emit() function in UX client script but seems it triggers only UX events.
I know we can achieve this using async BR but Is there any way to trigger script action from UX event or from UX Script Include?
Regards,
Nayan Awadhiya
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2023 06:21 AM
There are a couple of options available to you if you're looking to update a record from within UI Builder, but neither would involve a client script. Client scripts in UIB are primarily used for setting state values or firing events.
I would add the Update record data resource to the page and then call it on your button click, passing in the appropriate parameters to update the parent record with work notes.
The other option would come into play if this is a record page, where you can use a declarative action (or even UI action) to the the copy. If you can share more about the use case here we may be able to give more targeted recommendations.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2023 06:21 AM
There are a couple of options available to you if you're looking to update a record from within UI Builder, but neither would involve a client script. Client scripts in UIB are primarily used for setting state values or firing events.
I would add the Update record data resource to the page and then call it on your button click, passing in the appropriate parameters to update the parent record with work notes.
The other option would come into play if this is a record page, where you can use a declarative action (or even UI action) to the the copy. If you can share more about the use case here we may be able to give more targeted recommendations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2023 06:57 AM
Hi @nayanawadhiya1 ,
Hope you are doing great.
One approach is to create a server-side script action and invoke it from your UX event or UX Script Include.
1.create Script include
var CopyWorkNotesUtil = Class.create();
CopyWorkNotesUtil.prototype = {
initialize: function() {},
copyWorkNotesToParent: function(childTicketSysId, parentTicketSysId) {
// Fetch child ticket work notes using GlideRecord
var childTicketGR = new GlideRecord('incident');
if (childTicketGR.get(childTicketSysId)) {
// Copy work notes from child ticket to parent ticket
var parentTicketGR = new GlideRecord('incident');
if (parentTicketGR.get(parentTicketSysId)) {
parentTicketGR.work_notes = childTicketGR.work_notes;
parentTicketGR.update();
}
}
},
type: 'CopyWorkNotesUtil'
};
- In your UX client script, when the Custom UX Modal button is clicked, invoke the server-side script action using GlideAjax.
function copyWorkNotesToParent(childTicketSysId, parentTicketSysId) {
var ga = new GlideAjax('CopyWorkNotesUtil');
ga.addParam('sysparm_name', 'copyWorkNotesToParent');
ga.addParam('sysparm_child_ticket_sys_id', childTicketSysId);
ga.addParam('sysparm_parent_ticket_sys_id', parentTicketSysId);
ga.getXMLAnswer(function(response) {
// Handle the response if needed
});
}
​
- In your UX event or UX Script Include, call the copyWorkNotesToParent() function, passing the appropriate child and parent ticket sys_ids.
Regards,
Riya Verma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2023 08:14 AM
GlideAjax is not available in ux client scripts in UI Builder. The correct way to query or mutate data from UIB is to use a data resource.