Idea Portal Added Fields not writing to table

litchick10
Tera Guru

I have added 4 fields to the IM Create/Edit widget for the Idea Portal.  The fields work correctly on the form but 3 of the fields are not sending the data to the back end record

The fields types in the table are Reference (u_opened_for from sys_user, u_business_unit from business_unit) & List (u_collaborators from sys_user)

find_real_file.pngfind_real_file.png

 

I'm 99% sure it is in the client controller script that the issue is occurring. I have also added all fields to the Scripted Rest API code & Script Includes needed which is why Epic Hypothesis works. 

Here is my script for 3 fields not working:

Under

$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;
				 }
				},
// Add Collaborators field
			u_collaborators: {
				 label: $scope.data.messages.formLabels.u_collaborators,
				 name: $scope.data.messages.formLabels.u_collaborators,
				 stagedValue: ($scope.data.ideaInfo && $scope.data.ideaInfo.u_collaborators) || '',
				 value: '',
				 displayValue: '',
				 type: 'list',
				 mandatory: false,
				 mandatory_filled: function () {
				 return !!($scope.data.formModel._fields.u_collaborators.stagedValue);
				 },
				 isMandatory: function () {
				 return true;
				 }
				},
// Add benefiting businesss line field
			u_business_unit: {
				 label: $scope.data.messages.formLabels.u_business_unit,
				 name: $scope.data.messages.formLabels.u_business_unit,
				 stagedValue: ($scope.data.ideaInfo && $scope.data.ideaInfo.u_business_unit) || '',
				 value: '',
				 displayValue: '',
				 type: 'reference',
				 mandatory: true,
				 mandatory_filled: function () {
				 return !!($scope.data.formModel._fields.u_business_unit.stagedValue);
				 },
				 isMandatory: function () {
				 return true;
				 }
				}		

Under

var _getRequestParams = function (formFields, widgetMode) {
var requestParams = {};

requestParams.sysparm_u_epic = formFields.u_epic.stagedValue; //works
requestParams.sysparm_u_collaborators = formFields.u_collaborators.stagedValue;//does not work
requestParams.sysparm_u_business_unit = formFields.u_business_unit.stagedValue;//does not work
requestParams.sysparm_u_opened_for = formFields.u_opened_for.stagedValue;//does not work

 Scripted Rest API - Idea Portal Management --> Idea CUD Management under Create Idea

Under

if(operation == 'create') {

ideaInfo.u_epic = requestData.sysparm_u_epic;
ideaInfo.u_business_unit = requestData.sysparm_u_business_unit;
ideaInfo.u_opened_for = requestData.sysparm_u_opened_for;
ideaInfo.u_collaborators = requestData.sysparm_u_collaborators;

 

Script Includes (IMCreateEditIdeaDataService) replaced original content with this

var IMCreateEditIdeaDataService = Class.create();

IMCreateEditIdeaDataService.prototype = Object.extendsObject(IMCreateEditIdeaDataServiceSNC, {
  
createIdea: function(ideaInfo) {
 //gs.log('ideaInfo: ' + JSON.stringify(ideaInfo), 'IdeaPortal');
 var newIdeaSysId;
 var ideaGr = new GlideRecord(this.ideaTableName);
 ideaGr.initialize();
 ideaGr.setNewGuidValue(ideaInfo.sysId); //Setting sys_id here so that to fetch related attachments
 ideaGr.module = ideaInfo.module;
 ideaGr.short_description = ideaInfo.title;
 ideaGr.idea_description = ideaInfo.description;
 ideaGr.u_epic = ideaInfo.u_epic;
 ideaGr.u_collaborators = ideaInfo.u_collaborators;
 ideaGr.u_opened_for = ideaInfo.u_opened_for;
 ideaGr.u_business_unit = ideaInfo.u_business_unit;
 if(ideaGr.canCreate()) {
 newIdeaSysId = ideaGr.insert();
 //this.updateIdeaReferencesWithCategories(ideaInfo.categoryInfo,newIdeaSysId);
 this.createM2MReferencesForIdeaAndCategories(ideaInfo.categoryInfo,newIdeaSysId);
 this.updateEditorAttachments(ideaInfo.editorImages, newIdeaSysId);
 }

return {
 'sys_id': newIdeaSysId
 };
},
});

 

1 ACCEPTED SOLUTION
19 REPLIES 19

HTML Code - If there is a better way to add these types of fields, I'm totally open to changing the HTML...used comments to indicate where added. 

<div class="im_cq_wrapper row page-bg">
        <div ng-if="data.hasPermissions">
            <div class="col-md-12" ng-if="data.widgetMode == 'create'">
                <h2 class="h3">${Create an Idea}</h2>
            </div>
            <div ng-class="data.widgetMode == 'create' ? 'col-md-9 col-sm-9 col-xs-12' : 'col-md-12 col-sm-12 col-xs-12'">
                <uib-alert id="im-alert" ng-if="(formSubmitted && (!data.formModel._fields.title.stagedValue.trim() || data.formModel._fields.category.selectedCategoryId.length == 0 || !data.formModel._fields.description.stagedValue))" type="{{alertMessages.type}}">
                    <div class="msg-container">
                        <i class="fa fa-exclamation-circle" aria-hidden="true"></i>
                        <span class="message">{{alertMessages.msg}}</span>
                    </div>
                </uib-alert>
                <div class="panel panel-default">
                    <div class="panel-body">
                        <form name="forms.createForm" class="idea-form">
                            <div class="form-group title-field-container">
                                <label for="sp_form_field_title" class="field-label" title="{{data.label_hover_title}}"  aria-label="{{::data.formModel._fields.title.label}} "
                                    tooltip-right="true">
                                    <span class="field-decorations">
                                        <span ng-show="::data.formModel._fields.title.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.title.mandatory_filled()}"
                                            title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.title.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                                    </span>
                                    {{::data.formModel._fields.title.label}}
                                </label>
                              	<span ng-if="data.showIdeaSuggestion">
                                 	<sp-widget widget="::data.ideaTypeaheadSearch"></sp-widget>
                                  </span>
                              	<span ng-if="!data.showIdeaSuggestion">
                              		<input name="Title" id="sp_form_field_title" im-focus-element class="form-control" maxlength="{{data.maxLengthForTitleField}}" ng-class="(formSubmitted && !data.formModel._fields.title.stagedValue) ? 'field-invalid' : ''" data-type="{{::data.formModel._fields.title.type}}" ng-model="data.formModel._fields.title.stagedValue" ng-model-options="{allowInvalid: true}" ng-change="stagedValueChange()" autocomplete="off" ng-readonly="data.formModel._fields.title.isReadonly()" ng-attr-placeholder="{{data.formModel._fields.title.placeholder}}" type="text">
                              	</span>
                         </div>
                          <div id="results" class="col-xs-12 idea-search-results idea-page-view" data-ng-if="::data.showIdeaSuggestion">
                          </div>
                            <div class="form-group category-field-container">
                                <label for="categoryFltr" class="field-label" title="{{data.label_hover_category}}"  aria-label="{{::data.formModel._fields.category.label}} "
                                    tooltip-right="true">
                                    <span class="field-decorations">
                                        <span ng-show="::data.formModel._fields.category.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.category.mandatory_filled()}"
                                            title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.category.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                                    </span>
                                    {{::data.formModel._fields.category.label}}
                                </label>
                                <span class="type-{{::data.formModel._fields.category.type}} field-actual" ng-class="{'state-mandatory': data.formModel._fields.category.mandatory, 'state-readonly': data.formModel._fields.category.read_only, 'state-hidden': data.formModel._fields.category.hidden, 'has-error': data.formModel._fields.category.isInvalid}">
                                    <idea-category-select ng-class="(formSubmitted && data.formModel._fields.category.selectedCategoryId.length == 0) ? 'field-invalid' : ''" category-levels-text="data.messages.categoryLevelsText" categories="data.formModel._fields.category.optionsList"
                                        show-all-category-opt="false" selected-category-id="data.formModel._fields.category.selectedCategoryId"
                                        no-label="true" allow-multiple="true" category-opts="data.formModel._fields.category.config"
                                        multiple="true">
                                    </idea-category-select>
                                </span>
                                <p class="category_caption" ng-if="data._categorySelectionLimit > 1">{{::data.messages.categorySelectionLimitMsg}}</p>
                            </div>
<! -- Start adding choice fields -->
<! --  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" hint="Are you submitting this for someone else or yourself">
                                <span class="field-decorations">
                                    <span ng-show="::data.formModel._fields.u_opened_for.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.u_opened_for.mandatory_filled()}"
                                        title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.u_opened_for.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                                </span>
                                {{::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" ></sn-record-picker>
                          <p>&nbsp;</p>
<! --  Added Business Unit Selection -->                            
                          <label for="u_business_unit" class="field-label" title="{{data.label_hover_business_unit}}" aria-label="{{::data.formModel._fields.u_business_unit.label}} "
                                tooltip-right="true">
                                <span class="field-decorations">
                                    <span ng-show="::data.formModel._fields.u_business_unit.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.u_business_unit.mandatory_filled()}"
                                        title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.u_business_unit.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                                </span>
                                {{::data.formModel._fields.u_business_unit.label}}
                            </label>
							<sn-record-picker field="u_business_unit" table="'business_unit'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>
                          <p>&nbsp;</p>
<! --  Added Collaborators Selection -->          
   							<label for="u_collaborators" class="field-label" title="{{data.label_hover_collaborators}}" aria-label="{{::data.formModel._fields.u_collaborators.label}} "
                                tooltip-right="true">
                               <span class="field-decorations">
                                    <span ng-show="::data.formModel._fields.u_collaborators.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.u_collaborators.mandatory_filled()}"
                                        title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.u_collaborators.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                                </span>
                                {{::data.formModel._fields.u_collaborators.label}}
                            </label>
                          <sn-record-picker field="u_collaborators" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" multiple="true" page-size="100" ></sn-record-picker>
                          <p>&nbsp;</p>
<! --  End add Choice Fields -->                              
                            <label for="description" class="field-label" title="{{data.label_hover_description}}"  aria-label="{{::data.formModel._fields.description.label}} "
                                tooltip-right="true">
                                <span class="field-decorations">
                                    <span ng-show="::data.formModel._fields.description.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.description.mandatory_filled()}"
                                        title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.description.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                                </span>
                                {{::data.formModel._fields.description.label}}
                            </label>
                            <cf-tiny-mce
                                         ng-class="(formSubmitted && !data.formModel._fields.description.stagedValue) ? 'field-invalid' : ''"
                                         data-ng-model="data.formModel._fields.description.stagedValue"
                                         ng-model-options="{height: '300', allow: false}"
                                         table="{{data.formModel.table}}"
                                         attachment-sys-id="-1"
                                         max-file-size="{{data._maxAttachmentSize}}">
                           </cf-tiny-mce>
<! --Add Epic Hypothesis field -->  
                          <p>&nbsp;</p>
                          <label for="u_epic" class="field-label" title="{{data.label_hover_epic}}"  aria-label="{{::data.formModel._fields.u_epic.label}} "
                             tooltip-right="true">
                             <span class="field-decorations">
                             <span ng-show="::data.formModel._fields.u_epic.mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.formModel._fields.u_epic.mandatory_filled()}"
                             title="${Required}" style="padding-right: .25em" aria-label="{{data.formModel._fields.u_epic.mandatory_filled()? '${Required Filled}' : '${Required}'}}"></span>
                             </span>
                             {{::data.formModel._fields.u_epic.label}}
                             </label>
                             <cf-tiny-mce
                             ng-class="(formSubmitted && !data.formModel._fields.u_epic.stagedValue) ? 'field-invalid' : ''"
                             data-ng-model="data.formModel._fields.u_epic.stagedValue"
                             ng-model-options="{height: '300', allow: false}"
                             table="{{data.formModel.table}}"
                             attachment-sys-id="-1"
                             max-file-size="{{data._maxAttachmentSize}}">
                             </cf-tiny-mce>
                        </form>
                    </div>
                    <div class="panel-footer">
                        <div class="no-margin">
                            <div class="idea-attachment-list">
                                <div class="sp-attachments">
                                    <now-attachments-list template="im_attachment_preview"></now-attachments-list>
                                </div>
                            </div>
                            <label class="attachment-label" ng-class="data.widgetMode == 'create' ? 'right': 'left'">
                                <sp-attachment-button></sp-attachment-button>
                                <span>${Add attachments}</span>
                                <span class="clearfix"></span>
                            </label>
                            <div class="edit-idea-btn-actions" ng-if="data.widgetMode == 'edit'">
                                <button id="cancel_idea" class="btn btn-default " ng-click="cancelEditingIdea($event)">${Cancel}</button>
                                <button id="save_idea" class="btn btn-primary " ng-click="saveEditingIdea($event)">${Save}</button>
                            </div>
                            <span class="clearfix"></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-3 col-sm-3 col-xs-12 im_submit_cont" ng-if="data.widgetMode == 'create'">
                <button type="submit" id="submit_idea" class="btn btn-primary " ng-click="submitIdea($event)">${Create}</button>
            </div>
        </div>
        <div ng-if="!data.hasPermissions">
            <div class="alert alert-danger m-t" role="alert">
                ${Missing module/category configuration / Invalid module id!}
            </div>
        </div>
    </div>
<cf-confirm-modal data="modalConfig.opts" ng-if="modalConfig.showModal"></cf-confirm-modal>
<div class="loading-wrpr flex flex-center" ng-if="showLoading">
  <div class="flex flex-center flex-column">
    <div class="fa fa-spinner rotating"></div>
    <div ng-if="data.widgetMode == 'create'">${Creating idea...}</div>
    <div ng-if="data.widgetMode == 'edit'">${Saving idea...}</div>
  </div>
</div>

Can you try the alert which i told you in the client controller where you have written that value is not coming for u_opened by

 

I can't figure out how to do that properly.  Did this and now form won't submit

find_real_file.png

Hi Litchick

The same here you have to use

Put these alerts:

Use this alerts remove the a and alert

alert('Opened by '+ JSON.stringify($scope.u_opened_for));

alert('Opened by selected is ' + $scope.u_opened_for.value);

 

you are getting the error as the name is not define.

Thanks,

CB

Got this message just like you but how do I get the name defined? I'm just not sure where to define it. 

find_real_file.png

The second alert did not appear. Here is how I added to code

find_real_file.png