- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 09:53 AM
Hello everyone, hope you're all doing fine.
We are in need of some help, as we are trying to create a widget that is a Modal that receives a string input and saves on the comments field, but we can't seem to make it work because when we send the input value from the Client Controller to the Server Script it keeps coming as undefined.
I will provide you the codes we have.
Body HTML template:
<button ng-click="c.onOpen()" class="btn btn-default">
Prompt with label
</button>
<div ng-show="c.name">
You answered <span>{{c.name}}</span>
</div>
Client Controller:
api.controller = function($scope, spModal) {
var c = this;
c.onOpen = function() {
// Ask the user for a string
spModal.open({
title: 'Why do you want to cancel your ticket?',
message: 'Reason:',
input: true,
value: c.name || '' // Use empty string if c.name is initially undefined
}).then(function(name) {
if (name) { // Ensure input was provided
c.name = name;
c.server.update().then(function(response) {
});
});
};
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
var name = input.name;
var gr = new GlideRecord(data.table); // Ensure 'var' is used for variable declaration
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
//gr.setValue("comments", comments); // Use the input comments
gr.comments = name;
gr.update();
We appreciate any help you can provide and hopefully make it work!
Best Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 10:53 AM
Hi @joao_fonseca,
-------------------------------------------------------------------------------------------------------------------------------
You need to make few changes
in this code-->
if (name) { // Ensure input was provided
c.name = name;
c.server.update().then(function(response) {
});
if block "}" is missing
and the major change You have to use "c.data.name" instead of c.name in HTML and Client Script then your widget will work.
I tried it and it is working fine let me know if you still struggle.
------------------------------------------------------------------------------------------------------------------------------------
Please Mark my response as helpful and accept it as Solution.
Thanks & regards
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 10:53 AM
Hi @joao_fonseca,
-------------------------------------------------------------------------------------------------------------------------------
You need to make few changes
in this code-->
if (name) { // Ensure input was provided
c.name = name;
c.server.update().then(function(response) {
});
if block "}" is missing
and the major change You have to use "c.data.name" instead of c.name in HTML and Client Script then your widget will work.
I tried it and it is working fine let me know if you still struggle.
------------------------------------------------------------------------------------------------------------------------------------
Please Mark my response as helpful and accept it as Solution.
Thanks & regards
Mayank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 02:10 AM
It really worked, thank you very much!
I did marked your response as helpful and accept it as Solution.
T
hanks & regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 02:04 AM
If your query has been resolved, kindly mark my response as helpful or accept it as the solution so others can benefit as well.
------------------------------------------------------------------------------------------------------------------------------------
Please Mark my response as helpful and accept it as Solution.
Thanks & regards
Mayank