Component: NewEdit

 Show all Hide all

Displays a form that is edited/inserted into the database.

Component mode: Insert record

Displays an empty form to the user and inserts a new record in the database.

Supported modes: Insert record | Edit record | Duplicate record

Component settings

Cancel button text
Sets the label of the cancel button. Use either a custom text or a language phrase id.
Confirm close
Whether a warning should be shown when the user tries to leave the page while there are unsaved changes. The default value is taken from the NewEditConfirmClose application variable.

The message presented to the user is retrieved from language phrase 101160. Alter this phrase if a different wording than default is desired, or if the system supports additional languages.
Submit button text
Sets the label of the submit button. Use either a custom text or a language phrase id.

SQL

SQL Call: Retrieve column metadata (mandatory)

Retrieves metadata for the fields to edit in the form.
Supports custom errors: No
May modify database: No

Resultset: Specify number of columns

Specifies the number of columns to display forthcoming fields and how to allocate those fields to columns.
Repeat mode: repeated zero or more times
Row count: exactly one row

Columns:

admincolumns mandatory int
The number of columns to display forthcoming result sets.
adminlayout optional string
Specifies how the fields are allocated into columns.
If omitted the 'column' layout type is assumed.
Possible value Description
column The component expects n resultsets to follow and allocates the fields in the same resultset to a separate column.
row The component expects one resultset to follow where the n first fields are allocated to row one, the next n fields to row 2, etc... Fields on the same row will be aligned (middle) with each other.

Resultset: Fields to edit

Repeat mode: repeated one or more times
Row count: no rows (only column metadata)

Columns:

<fieldname> optional string
Field to display in form. If there exists a querystring parameter with the same name as the field, then the field will be automatically hidden and have its value set to the querystring parameters value.

Resultset: Dynamic field information

Specify extra field information for the fields on the page.
Repeat mode:
Row count:

Columns:

<xxx> optional string
Set property <xxx> for the field specified in adminfieldname. If set to null the value will not be applied.
AdminFieldName mandatory string
The name of the field to apply the information to. The presence of this column indicates that the resultset specifies field information.
ButtonJavaScript<xxx> optional string
Inserts a button next to the control that is used to execute the JavaScript supplied here. <xxx> is an arbitrary text that can be empty if only one button is required.
ButtonJavaScript<xxx>_Label optional string
The label for the JavaScript button <xxx>.
CellAlignment optional string
Specifies the alignment of the text in the field.
Possible value Description
Center Center aligned.
Left Left aligned.
Right Right aligned.
ColumnTooltip optional string
Sets the tooltip on the column title. Only supported by the Grid component.
DefaultValue optional string
The default value for the control or if prefixed by 'SQL:' the sql to run to determine the default value.
Description optional string
The description for the field.
EnabledJavaScript optional string
Javascript that controls the enabled status of the field. The control is only enabled if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed. This is only available to control types for which the enabled javascript field is visible in the user interface.
FieldGroupId optional int
The field group to use.
FieldInfoId optional int
ID of field information to base the dynamic field on. All properties not explicitly overridden by dynamic field information will be copied from this field. The referenced field must be found in the menu item's field tables.
FieldLabel optional string
If present the field label is used as the heading for fields instead of the field name.
FieldType optional string
The name of the control type to use.
Height optional int
The height of the control.
IgnoreOnSave optional bit
Do not pass the field value to the insert/update procedure.
InfoSqlLayout optional string
Where the label is shown in relation to the contents in InfoSQL.
Possible value Description
LabelAbove Full width, label above.
NoLabel Full width, no label.
Standard Label to the left.
NullChoice optional bit
Specifies whether the control allows null values.
NumberOfDecimals optional int
The number of decimals to display for numeric values.
OnChangeJavaScript optional string
Javascript run when the value of the control has changed.
OutputFormat optional string
Special formatting to be applied when the field is displayed.
Possible value Description
Hyperlink
MailToLink
PhoneLink
Placeholder optional string
Text shown when the field is empty.
Sql optional string
The SQL that determines the control's behavior. (Refer to control documentation for more information)
ThousandDelimiter optional string
The thousand grouping delimiter for numeric values.
Width optional int
The width of the control.
VisibleJavaScript optional string
JavaScript that controls the visibility of the field. The control is only visible if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed.

Resultset: Button specification

Overrides the standard Save and Cancel buttons.
Repeat mode:
Row count:

Columns:

adminbuttonid mandatory string
The specified adminbuttonid is passed to the insert/update procedure in the @adminbuttonid parameter when the button is clicked.

If this column is null the button will act as the default save button, i.e. the @adminbuttonid paramter will not be supplied and the button will be triggered by the Ctrl+S and Enter keyboard shortcuts.
buttontext optional string
The text of the button.
If both PhraseId and ButtonText are null the default save button phrase will be used, unless CidStepsBack is non null. If CidStepsBack is non-null the default Cancel button phrase will be used.
cidstepsback optional int
If specified, the button acts as a cancel button, i.e. the InsertUpdate procedure will not be called and the cancel action will be triggered. The button also responds to the Esc keyboard shortcut.
If omitted the button will not be a cancel button.
phraseid optional string
Phrase id for the text of the button.
If both PhraseId and ButtonText are null the default save button phrase will be used, unless CidStepsBack is non null. If CidStepsBack is non-null the default Cancel button phrase will be used.

Resultset: JavaScript lookup functions

If you have fixed lookup tables that fields need for visibility scripts then you can have NewEdit generate JavaScript lookup functions.

For example

SELECT
ComponentId AS ADMINJavaScriptLookup,
HasComponentSql AS componentHasSql,
HasInfoSql AS componentHasInfoSql
FROM dbo.ADMINComponent
Repeat mode: repeated zero or more times
Row count: zero or more rows

Columns:

ADMINJavaScriptLookup mandatory int
This must be the first column in the table.
xxx mandatory int
For each column xxx a JavaScript function xxx is generated. The function maps the id values in the ADMINJavaScriptLookup-column to the values in the xxx-column.

If this is a bit column then the SQL value 1 is converted to the JavaScript value true, and both 0 and NULL are converted to false.

SQL Call: Validate parameters

Allows you to validate the parameters supplied by the user before any other SQL is run in the component. This call is only made if the component has visible parameters, the SQL is a stored procedure, and 'Validate parameters' is checked.
Supports custom errors: No
May modify database: No

Parameters:

@force optional bit
@validateparams mandatory bit
This parameter is set to 1 by Softadmin® when this call is made.

Insert/Update/Delete SP

SQL Call: Insert record (mandatory)

Inserts a new record into the database.
Supports custom errors: Yes
May modify database: Yes

Resultset: Clear cache and forwarding definitions

Specify which menuitem to forward to and clear any cached data that has been invalidated.
Repeat mode:
Row count:

Columns:

<querystring_variable> optional string
Any column with no other specific meaning will pe passed along on the querystring to the menuitem you are forwarding to.
admin_cancelcidstepsback optional int
Number of steps in the page history to jump back if the user clicks OK in an ADMIN_MESSAGE dialog or Cancel in an ADMIN_FORCE dialog (the default being none). This value overrides cancelcidstepsback specified in the query string.
admin_cancelmenuitemid optional int
Id of the menuitem to execute if the user clicks OK in an ADMIN_MESSAGE dialog or Cancel in an ADMIN_FORCE dialog (the default being none). This value overrides cancelmenuitemid specified in the query string.
admin_cidstepsback optional int
Number of steps in the page history to jump back after execution (the default being one step back). This value overrides any destination specified by the query string.
admin_force optional string
Prompts the user with the specified text and the user may answer OK or cancel. If the user chooses OK the sql call will be rerun with the parameter @force set to 1.
admin_forward optional string
Displays a user friendly message and then forwards to the next menu item.
admin_forwardmenugroupid optional int
Id of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.
admin_forwardmenuitemid optional int
Id of the menuitem to execute after execution (instead of former menu item). This value overrides any destination specified by the query string.
admin_message optional string
Displays a user friendly message to the user.
admin_pastehtmlfrompopup optional string
Pastes HTML. See admin_setfieldvaluefrompopup
admin_setfieldvaluefrompopup optional string
Sets the value of field specified in the menuitempopup call. Only select this column if menuitem is opened in popup.
admin_closepopup optional bit
If this column is anything but NULL the popup will be closed. Only select this column if the menuitem is opened in popup.
The default behavior is to step back inside the popup window and close it if there is nothing to step back to.
admin_unselect optional bit
Alias for ADMIN_UnselectAll.
Cache optional string
Cache key to be cleared. Supports wildcards.
CacheUserId optional string
Either a user id or '%'.

Clears all caches (e.g. access permissions) related to the specified user id.

Use '%' to clear caches for all users.
cancelbuttontext optional string
Changes the text of the Cancel button when used with ADMIN_Force.
okbuttontext optional string
Changes the text of the OK button when used with ADMIN_Message, ADMIN_Force, or ADMIN_Forward.

Info SQL

SQL Call: InfoSql (2008)

SQL that can have several resultsets that are displayed at top of component.
Supports custom errors: No
May modify database: No

Resultset: Main title

Specifies the main title.
Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

maintitle optional string
The main title.

Resultset: Box

Defines one or more boxes to display.
Repeat mode: repeated zero or more times
Row count: one or more rows

Columns:

Title optional string
The title of the box.
TitleIconId optional int
Displays an icon next to the box title.
TitleIconBadgeId optional int
Override menuitem badge.
ColumnSpan optional int
Specifies the column span for the box. If this is above one the box will be displayed on a separate row.
LinkId optional int
Displays the specified link among the top links and in the title row of the box. The link will only appear in the title row if no ordinary columns lie before it in the resultset.

Columns named PassingField_<xxx> will not be shown in the box and can be referenced from the link as a Column value with name <xxx>.

LinkId and MenuItemId can not be used at the same time.

Multiple LinkId columns may appear in a single resultset.
MenuItemId optional int
Recomended to use LinkId instead for better tracking of links.

Displays a link to the menu item with this id among the top links and in the title row of the box. The link will only appear in the title row if no ordinary columns lie before it in the resultset.

LinkId and MenuItemId can not be used at the same time.

Multiple MenuItemId columns may appear in a single resultset.
NavigatorLinkText optional string
Used in combination with menuitemid to give the navigator link a text that differs from the name of the menu item.

If explicitly set to NULL the link will not be shown in the navigator but may still appear as a link in the title of a box.
PassingFields optional string
Additional information to 'menuitemid', appends values to querystring (supports simple Softadmin® parameters).

Multiple passingfield columns may appear in a single resultset. Passingfields will normally be connected with the closest preceeding menuitemid column, but see the note below regarding the title link.

NOTE: The first passingfield column will be used for the title link regardless of whether there is another menuitemid column in between.
<colname> optional string
Value displayed in the box with heading defined by field information or column name.
<colname>_Color optional string
Sets the text color of <colname> to the specified color using #RRGGBB color code or HTML color name. If using color names then you must use American spellling (for example gray, not grey).
<colname>_Icon optional string
The name of the system icon to show before the <colname> value.

Use the menu item "Admin>Theme>System icons" to register system icons.
<colname>_IconColor optional string
Color in #RRGGBB format to use for the icon specified in <colname>_Icon.
<colname>_LinkId optional int
Creates a cell link with the specified link id for the <colname> cell.

PassingField_<xxx> columns can be referenced from the link.

<colname>_LinkId and <colname>_MenuItemId can not be used at the same time.
<colname>_MenuItemId optional int
Supplies a link to the menu item with the specified menuitemid when used in conjunction with <colname>.
<colname>_PassingFields optional string
Supplies the querystring when used in conjunction with <colname>_MenuItemId.
<colname>_Style optional string
Sets the CSS style for <colname>.
<colname>_Tooltip optional string
Sets the tooltip for <colname>.
PlaintextFull, PlaintextLeft, PlaintextRight optional string
These columns are deprecated. Use either PlainText, Html or SafeHtml instead, depending on what behavior you need.

The content of this column will be treated as Html, but line breaks and non-breaking spaces will be converted to br-tags. In future versions this column will be escaped.
PlainText optional string
Displays plain text without a column title, i.e. occupies the entire vertical space available in the box. Any HTML in the text will be escaped.
Html optional string
Displays HTML without a column title, i.e. occupies the entire vertical space available in the box. Uses the Layouted HTML level to determine allowed elements and attributes.

If the Html-column is too restrictive for your needs then use the SafeHtml-column instead.
SafeHtml optional string
Displays HTML without a column title, i.e. occupies the entire vertical space available in the box. Uses the Safe HTML level to determine allowed elements and attributes.

The SafeHtml-column is less restrictive than the Html-column. Use it only when you need it.
WarningInfo optional string
The text will be at the top of the menuitem and displayed in blue.
Warning optional string
The text will be at the top of the menuitem and displayed in yellow.
WarningError optional string
The text will be at the top of the menuitem and displayed in red.
Javascript optional string
The column is hidden from the user and treated as a javascript to be included in the HTML.
StartExpanded optional bit
Whether the infobox should start expanded or collapsed. NULL/Ommited means default behavior, all expanded on big screens, only first expanded on small screens.
PassingField_<xxx> optional string
Can be used by links referenced by <colname>_LinkId or LinkId columns. Not shown in InfoSQL.
QrCode optional string
A QR Code will be rendered containing the text in the column.

Resultset: Dynamic field information

Specify extra properties for fields in the InfoSql.
Repeat mode:
Row count:

Columns:

<xxx> optional string
Set property <xxx> for the field specified in adminfieldname. If set to null the value will not be applied.
AdminFieldName mandatory string
The name of the field to apply the information to. The presence of this column indicates that the resultset specifies field information.
ButtonJavaScript<xxx> optional string
Inserts a button next to the control that is used to execute the JavaScript supplied here. <xxx> is an arbitrary text that can be empty if only one button is required.
ButtonJavaScript<xxx>_Label optional string
The label for the JavaScript button <xxx>.
CellAlignment optional string
Specifies the alignment of the text in the field.
Possible value Description
Center Center aligned.
Left Left aligned.
Right Right aligned.
ColumnTooltip optional string
Sets the tooltip on the column title. Only supported by the Grid component.
DefaultValue optional string
The default value for the control or if prefixed by 'SQL:' the sql to run to determine the default value.
Description optional string
The description for the field.
EnabledJavaScript optional string
Javascript that controls the enabled status of the field. The control is only enabled if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed. This is only available to control types for which the enabled javascript field is visible in the user interface.
FieldGroupId optional int
The field group to use.
FieldInfoId optional int
ID of field information to base the dynamic field on. All properties not explicitly overridden by dynamic field information will be copied from this field. The referenced field must be found in the menu item's field tables.
FieldLabel optional string
If present the field label is used as the heading for fields instead of the field name.
FieldType optional string
The name of the control type to use.
Height optional int
The height of the control.
IgnoreOnSave optional bit
Do not pass the field value to the insert/update procedure.
InfoSqlLayout optional string
Where the label is shown in relation to the contents in InfoSQL.
Possible value Description
LabelAbove Full width, label above.
NoLabel Full width, no label.
Standard Label to the left.
NullChoice optional bit
Specifies whether the control allows null values.
NumberOfDecimals optional int
The number of decimals to display for numeric values.
OnChangeJavaScript optional string
Javascript run when the value of the control has changed.
OutputFormat optional string
Special formatting to be applied when the field is displayed.
Possible value Description
Hyperlink
MailToLink
PhoneLink
Placeholder optional string
Text shown when the field is empty.
Sql optional string
The SQL that determines the control's behavior. (Refer to control documentation for more information)
ThousandDelimiter optional string
The thousand grouping delimiter for numeric values.
Width optional int
The width of the control.
VisibleJavaScript optional string
JavaScript that controls the visibility of the field. The control is only visible if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed.

Resultset: Dynamic top links

Defines one or more links to be shown among the top links.
Repeat mode: repeated zero or more times
Row count: zero or more rows

Columns:

LinkId optional int
See the "Box" resultset documentation.
MenuItemId mandatory int
Recomended to use LinkId instead for better tracking of links.

Displays a link to the menu item with this id among the top links. The title of the box will also turn into a link when the user hovers the mouse.
NavigatorLinkIconBadgeId optional int
Used in combination with menuitemid or LinkId to give the navigator link an icon that differs from the icon badge of the menu item.
NavigatorLinkIconId optional int
Used in combination with menuitemid or LinkId to give the navigator link an icon that differs from the icon of the menu item. Only one of navigatorlinkiconid and navigatorlinkiconname can have a value.
NavigatorLinkText optional string
Used in combination with menuitemid to give the navigator link a text that differs from the name of the menu item.
PassingField_<xxx> optional string
See the "Box" resultset documentation.
PassingFields optional string
Additional information to 'menuitemid', appends values to querystring (supports simple Softadmin® parameters).

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.
Supports custom errors: No
May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.

URL

Querystring parameters

menuitemheading optional
String that replaces the menu item name when the menu item is loaded. It does not replace the name before that (like for example in the navigator). It is ignored if the menu item is displayed as a part in a multipart in which case the name can be set from the multipart procedure.

Examples

How to handle transactions

Avoid using nested transactions (since only the outermost matters regarding ROLLBACK or COMMIT). The following code only starts transactions when necessary, ie if one has not already been started. Make sure to look at the @IsUsingLocalTransaction parameter before any COMMITs or ROLLBACKs.

-----------------------
-- Begin transaction --
-----------------------

DECLARE
	@IsUsingLocalTransaction	bit

IF @@TRANCOUNT = 0
BEGIN
	SET XACT_ABORT ON
	BEGIN TRANSACTION

	SELECT
		@IsUsingLocalTransaction = 1
END

--------------------------
-- INSERT/UPDATE/DELETE --
--------------------------

<DML statements>

------------------------
-- Commit transaction --
------------------------

IF @IsUsingLocalTransaction = 1
BEGIN
	COMMIT TRANSACTION
END

Dynamic field info - NewEdit

Example of how dynamic field info can be used to change the properties of fields in a NewEdit.

ALTER PROCEDURE Example.NewEdit_DynamicFieldInfoGetEditFields
AS
BEGIN

	-----------------------
	-- Fields to NewEdit --
	-----------------------

	SELECT
		-- In this example, this field keeps its original field info
		CONVERT(varchar(1000), NULL) AS [ExampleFieldChangedByDynamicFieldInfo1],
		-- And these fields will have their field changed by dynamic field info
		CONVERT(varchar(1000), NULL) AS [ExampleFieldChangedByDynamicFieldInfo2],
		CONVERT(varchar(1000), NULL) AS [ExampleFieldChangedByDynamicFieldInfo3],
		CONVERT(varchar(1000), NULL) AS [ExampleFieldChangedByDynamicFieldInfo4]

	------------------------
	-- Dynamic field info --
	------------------------

	/*
		You don't have to SELECT all dynamic field info in one result set,
		the presence of the column [ADMINFieldName] in the result sets tells
		Softadmin® that the result set specifies dynamic field info.

		The basic structure is to specify the field to change in a column [ADMINFieldName],
		the other columns are the properties to be changed. NULL values are
		interpreted as keeping the static field info.
	*/
	
	SELECT
		-- Field to change
		'ExampleFieldChangedByDynamicFieldInfo2' AS [ADMINFieldName],
		-- Properties to change
		'Look how I''ve changed the label but not the description' AS [FieldLabel],
		NULL AS [Description]	-- NULL value, original description will be used

	SELECT
		-- Field to change
		 'ExampleFieldChangedByDynamicFieldInfo3' AS [ADMINFieldName],
		-- Properties to change
		 'Look how I''ve changed the description, width and height' AS [Description],
		 400 AS [Width],
		 225 AS [Height]

	SELECT
		-- Field to change
		 'ExampleFieldChangedByDynamicFieldInfo4' AS [ADMINFieldName],
		-- Properties to change
		 'Look how I''ve changed the label, type and default value' AS [FieldLabel],
		 'Uneditable text' AS [FieldType],
		 '* Try and change me if you can *' AS [DefaultValue]

END

Using progress output

This code demonstrates how to use the process functions to maintain a progress bar during processing.

CREATE TABLE #ToPostProcess
(
	ThingyId int not null
);

 /* Choose things to post-process here */
INSERT #ToPostProcess (ThingyId)
SELECT n
FROM SoftadminUtil.Number_Range(1,5);

EXEC SoftadminApi.Progress_SetTitle
	@TitleText = 'Post processing thingies';

DECLARE
	@CompletedSteps int = 0,
	@TotalSteps int = (SELECT COUNT(*) FROM #ToPostProcess);

DECLARE ThingyCursor CURSOR LOCAL FOR
SELECT
	ThingyId
FROM
	#ToPostProcess;

OPEN ThingyCursor;
WHILE 1=1
BEGIN
	EXEC SoftadminApi.Progress_SetStep
		@CompletedSteps = @CompletedSteps,
		@TotalSteps     = @TotalSteps;

	DECLARE @ThingyId int;
	FETCH ThingyCursor INTO @ThingyId;

	IF @@FETCH_STATUS <> 0
		BREAK;

	/* Post-process Thingy with id @ThingyId here */
	-- EXEC Example.Thingy_PostProcess @ThingyId = @ThingyId;

	SET @CompletedSteps += 1;
END
CLOSE ThingyCursor;
DEALLOCATE ThingyCursor;

DROP TABLE #ToPostProcess;

Best practice

Name of stored procedures

The edit fields stored procedure should be named "<Schema>.<Table>_GetEditFields". The insert/update procedureshould be named "<Schema>.<Table>_InsertUpdate" (or just "Insert" or "Update" if the procedure doesn't handle both actions).