How to write client controller and server script ?

sneha64
Tera Contributor

Hello,

I'm a novice when it comes to building widgets.

Instead of using catalog client script and script include, I have a requirement that we write our logic in widget (using client controller and server script)

I've already written the logic, and it's working fine.
Can somebody assist me in building the client controller and server scripts for this?

 

Catalog Client script code:

var ga = new GlideAjax('saveDefaultDeliveryPreferences');
ga.addParam('sysparm_name','savingCountryAndDeliverAddress');
ga.addParam('sysparm_country', g_form.getValue('country'));
// ga.addParam('sysparm_delivery', g_form.getValue("delivery_address"));
ga.getXML(updatePrefernceDetails);
function updatePrefernceDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

 

Script include code:

var saveDefaultDeliveryPreferences = Class.create();
saveDefaultDeliveryPreferences.prototype = Object.extendsObject(AbstractAjaxProcessor, {
savingCountryAndDeliverAddress: function(){

var country;
var currentUser = gs.getUser();
var sysId = this.getParameter("sysparm_country");
if (sysId) {
var gr = new GlideRecord("cmn_location");
if (gr.get(sysId)) {
country = gr.getValue("country");
}
}
country = JSON.stringify(country);
currentUser.savePreference('defaultCountry',country);

},
type: 'saveDefaultDeliveryPreferences'
});

 

Regards,

Sneha

1 ACCEPTED SOLUTION

Couple of links are mentioned below which are quite good for learning Service POrtal widgets:

https://www.youtube.com/watch?v=Jav32aDEz1I

https://www.youtube.com/watch?v=0gz3XzBM-Gs

https://developer.servicenow.com/print_page.do?release=paris&category=courses&identifier=app_store_learnv2_serviceportal_paris_service_portal&module=course

 

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/concept/widget-dev-guide.html

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/concept/adv-widget-tutorial.html

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

8 REPLIES 8

This line "and I need to capture their details based on user preference in order to avoid modifying the sys_user table." is not clear to me on what you are trying to accomplish here.

 

Your widget looks okay to me. If you can let me know your detailed requirement, I can help you to modify your widget code accordingly and achieve what you want here.

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

sneha64
Tera Contributor

Requirement:

  • Client wants to store some information related to the user during ordering process.
  • The user will be asked if he wants to keep these information for the next order.
 

Solution

  • The idea is to use “user preference” capability instead of modifying the sys_user table.
  • Those are visible only for the user (he can see only his own preferences) and the administrators.
Example
In variable set itaas_delivery (which is present on almost all items), country and delivery address are information that can be used for this POC.
 
Order guide is:
find_real_file.png
 
above is the catalog item inside order guide when user choose the option.
 
Here the client want to store the country detail based on user so that when the user again ordering the same thing then country name will picked via user prefernce table not using sys_user table.
 
Regards,
Sneha

sneha64
Tera Contributor
Thanks for sharing the information. Please let me know where I can learn about how to create logic in client controllers, server side scripts as HTML, and angularjs I'm aware of. Regards, Sneha

Couple of links are mentioned below which are quite good for learning Service POrtal widgets:

https://www.youtube.com/watch?v=Jav32aDEz1I

https://www.youtube.com/watch?v=0gz3XzBM-Gs

https://developer.servicenow.com/print_page.do?release=paris&category=courses&identifier=app_store_learnv2_serviceportal_paris_service_portal&module=course

 

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/concept/widget-dev-guide.html

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/concept/adv-widget-tutorial.html

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke