Idea Portal Widget IM Create/Edit - added fields not writing to table

litchick10
Tera Guru

I have modified the IM Create/Edit widget by adding a field called "Opened For" that allows selection from the Sys_User table.  The problem is that the value is not writing to the idea table. Using an alert, I've determined that the value is "Undefined" so therefore cannot write to table. I don't know how to query the Sys_User table for the field to get the value.

I am Extremely new to widget development and am really struggling

Here are the changes made to the widget:

HTML added field:

<! --  Added Requested for Sys User Unit Selection -->   
      <label for="u_opened_for" 
             class="field-label" 
             title="{{data.label_hover_opened_for}}" 
             aria-label="{{::data.formModel._fields.u_opened_for.label}} "
             tooltip-right="true" 
                              {{::data.formModel._fields.u_opened_for.label}}
        </label>
        <sn-record-picker field="u_opened_for" 
                                table="'sys_user'" 
                                display-field="'name'" 
                                value-field="'sys_id'" 
                                search-fields="'name'" 
                                page-size="100" >

Server Script - added label only

//hover over 
data.label_hover_opened_for = "Are you submitting this for another associate or yourself";

data.messages.formLabels = {
'title': gs.getMessage('Title'),
'category': gs.getMessage('Category'),
'description': gs.getMessage('Description'),
'u_epic': gs.getMessage('Idea Details'),
'u_collaborators': gs.getMessage('Collaborators'),
'u_business_unit': gs.getMessage('Benefiting business line'),
'u_opened_for': gs.getMessage('Opened for')

Client Controller

   $scope.data.formModel = {
        _fields: {
// Add Opened for field
	u_opened_for: {
		label: $scope.data.messages.formLabels.u_opened_for,
		name: $scope.data.messages.formLabels.u_opened_for,
		stagedValue: ($scope.data.ideaInfo && $scope.data.ideaInfo.u_opened_for) || '',
		value: '',
		displayValue: '',
		type: 'reference',
		mandatory: true,
		mandatory_filled: function () {
		return !!($scope.data.formModel._fields.u_opened_for.stagedValue);
		},
		isMandatory: function () {
		return true;
		}
		},
  var _getRequestParams = function (formFields, widgetMode) {
        var requestParams = {};
        requestParams.sysparm_sys_id = $scope.data._attachmentTableSysId;
        requestParams.sysparm_u_opened_for = formFields.u_opened_for.stagedValue//does not work
   } 

I have updated the script includes/scripted rest api for idea to send the info from sys_parm_u_opened_for to table but because this value is undefined, it cannot write it.

Here is what form looks like:

find_real_file.png

 

1 ACCEPTED SOLUTION

UPDATE: 11/14/23 - This code was working and it no longer works. We are on Utah version.  I'm not sure at what point this quit working but I'm trying to figure out a new solution

 

Thanks this did help. It wasn't quite the right answer but close.

Make the following changes to the client script:

Add

  $scope.u_opened_for = {
 displayValue: $scope.data.u_opened_for.name,
 value: $scope.data.u_opened_for.sys_id,
 name: 'u_opened_for'
 };

Add

 $scope.$on("field.change", function(evt, parms) {
 if (parms.field.name == 'u_opened_for'){
 c.data.setu_opened_for = parms.newValue;
 }});

Don't change anything on this part of the client script section

// Add Opened for field
			u_opened_for: {
				 label: $scope.data.messages.formLabels.u_opened_for,
				 name: $scope.data.messages.formLabels.u_opened_for,
				 stagedValue: ($scope.data.ideaInfo && $scope.data.ideaInfo.u_opened_for) || '',
				 value: '',
				 displayValue: '',
				 type: 'reference',
				 mandatory: true,
				 mandatory_filled: function () {
				 return !!($scope.data.formModel._fields.u_opened_for.value);
				 },
				 isMandatory: function () {
				 return true;
				 },
				},

change

  requestParams.sysparm_u_business_unit = formFields.u_opened_for.stagedValue;

to
  requestParams.sysparm_u_opened_for = $scope.u_opened_for.value;

 

Add the following to the server script

 data.u_opened_for = {
  'name': '',
  'sys_id':''
  };

And voila it works!

View solution in original post

21 REPLIES 21

Ct111
Giga Sage

Check the below link it will help you to understand how to fetch vlaue in record picker.

https://serviceportal.io/sn-record-picker/

 

Mark my ANSWER as CORRECT and HELFPUL if it helps

I wasn't able to get this to work and I suspect is because I'm using the formModal fields.  see notes in green below. Tried adding the field outside Modal but then if I tried to set the requestParams value the form won't load (navigates to page but no form shown) 

   $scope.data.formModel = {
        _fields: {
// Add Opened for field
u_opened_for: {
label: $scope.data.messages.formLabels.u_opened_for,
name: $scope.data.messages.formLabels.u_opened_for,
stagedValue: ($scope.data.ideaInfo && $scope.data.ideaInfo.u_opened_for) || '',
value: '',//When adding the c.data.loc.sys_id here the form no longer loads
displayValue: '',//When adding the c.data.loc.name here the form no longer loads
type: 'reference',
mandatory: true,
mandatory_filled: function () {
return !!($scope.data.formModel._fields.u_opened_for.stagedValue);
},
isMandatory: function () {
return true;
}
},
  var _getRequestParams = function (formFields, widgetMode) {
        var requestParams = {};
        requestParams.sysparm_sys_id = $scope.data._attachmentTableSysId;
        requestParams.sysparm_u_opened_for = formFields.u_opened_for.stagedValue//form won't load if using $scope.data.u_opened or $scope.data.u_opened.value
   }

 

$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'u_opened_for')
c.data.setu_opened_for = parms.newValue;//doesn't set staged value/write to table. If using $scope.data.u_opened_for.stagedValue instead of highlighted text still doesn't write to table
 
c.server.update().then(function(response) {
spUtil.update($scope);
})
});
 
 
 
Also tried adding the "ng-class="(formSubmitted && !data.formModel._fields.u_opened_for.stagedValue)" in the HTML and the form won't load with this added to the html for the picker.  I'm wondering if it is because I shouldn't use an SN-Picker but some other type of field add.

UPDATE: 11/14/23 - This code was working and it no longer works. We are on Utah version.  I'm not sure at what point this quit working but I'm trying to figure out a new solution

 

Thanks this did help. It wasn't quite the right answer but close.

Make the following changes to the client script:

Add

  $scope.u_opened_for = {
 displayValue: $scope.data.u_opened_for.name,
 value: $scope.data.u_opened_for.sys_id,
 name: 'u_opened_for'
 };

Add

 $scope.$on("field.change", function(evt, parms) {
 if (parms.field.name == 'u_opened_for'){
 c.data.setu_opened_for = parms.newValue;
 }});

Don't change anything on this part of the client script section

// Add Opened for field
			u_opened_for: {
				 label: $scope.data.messages.formLabels.u_opened_for,
				 name: $scope.data.messages.formLabels.u_opened_for,
				 stagedValue: ($scope.data.ideaInfo && $scope.data.ideaInfo.u_opened_for) || '',
				 value: '',
				 displayValue: '',
				 type: 'reference',
				 mandatory: true,
				 mandatory_filled: function () {
				 return !!($scope.data.formModel._fields.u_opened_for.value);
				 },
				 isMandatory: function () {
				 return true;
				 },
				},

change

  requestParams.sysparm_u_business_unit = formFields.u_opened_for.stagedValue;

to
  requestParams.sysparm_u_opened_for = $scope.u_opened_for.value;

 

Add the following to the server script

 data.u_opened_for = {
  'name': '',
  'sys_id':''
  };

And voila it works!

@litchick10  we are trying it in same way, but the script did not worked. Whatever business unit was entered through widget did not came when opened in platform.

Please point the exact modifications to be done. Attaching the reference script for same.