Restrict the creation of sub project

Jira -AQ-2931

This is mainly using client script scripting .

Client scripts are scripts that are executed by predefined event triggers in the client browser. They can
validate user-entered data and auto-populate fields or sublists at various form events.

Client scripts only execute in edit mode. If you have a deployed client script with a
pageInit entry point, that script does not execute when you view the form. It executes when you
click Edit.

The following triggers can run a client script.
■ Loading a form for editing
■ Entering or changing a value in a field (before and after it is entered)
■ Entering or changing a value in a field that sources another field
■ Selecting a line item on a sublist
■ Adding a line item (before and after it is entered)
■ Saving a form

The main Entry point used here is pageInit and saveRecord.

pageInit Entry point ::

Defines the function that is executed after the page completes loading or when the form is reset.
The following sample tasks can be performed:
■ Populate field defaults.
■ Disable or enable fields.
■ Change field availability or values depending on the data available for the record.
■ Add flags to set initial values of fields.
■ Provide alerts where the data being loaded is inconsistent or corrupt.
■ Retrieve user login information and change field availability or values accordingly.
■ Validate that fields required for your custom code (but not necessarily required for the form)
exist.

Parameters

scriptContext.currentRecord : The current form record For more information about
CurrentRecord object members.

scriptContext.mode :

The mode in which the record is being accessed. The mode can be set to one of the following values:

■ copy
■ create
■ edit

Sample program

define([‘N/error’],
function(error) {
function pageInit(context) {
if (context.mode !== ‘create’)
return;
var currentRecord = context.currentRecord;
currentRecord.setValue({
fieldId: ‘entity’,
value: 107
});
}

The next entry point used here is

saveRecord

Defines the function that is executed when a record is saved (after the submit button is pressed but
before the form is submitted).
The following sample tasks can be performed:
■ Provide alerts before committing the data.

■ Enable fields that were disabled with other functions.
■ Redirect the user to a specified URL.

Returns true if the record is valid and is saved.
false otherwise.

Parameters used is

scriptContext.currentRecord ::

The current form record.
For more information about CurrentRecord object members

Sample Program

function saveRecord(context)

{ var currentRecord = context.currentRecord;

if (!currentRecord.getValue({

fieldId: ‘entity’

})

|| currentRecord.getLineCount({

sublistId: ‘item’

}) < 1)

throw error.create({

name: ‘MISSING_REQ_ARG’,

message: ‘Please enter all the necessary fields on the salesorder before saving’

});

return true;

}

Leave a comment

Your email address will not be published. Required fields are marked *