top of page
OmniStudioFactBg.png
  • Writer's pictureGayathiri Mohan

Edit Block in OmniScript

Updated: Jul 10

An Edit Block element in Omniscript allows the user to create, edit, and delete multiple records. To accomplish this, the edit blocks are repeatable blocks by default.

Let us see an example to use an Edit Block in Omniscript to handle multiple records.

In our example, we will use an Edit Block to display all the existing Contacts linked to an Account and also create, edit, and delete contacts directly from the Edit Block.


  • In the Omniscript, a new DataRaptor Extract Action is added.


  • Here,  ‘DRExtractContactsPOC’ is the DataRaptor Extract that retrieves all the Contacts linked to an Account based on the ‘AccountId’ filter value passed to it.



  • Now a Step element is added to the Omniscript, and an Edit Block is added inside the step.


  • Here, ‘Contacts’ is the unique name of the Edit Block element. In order to use the values from the DataRaptor Extract Action, the name of the Edit Block should match the name of the output array returned from the DataRaptor Extract Action.


  • Table’ is the Edit Block Mode. This displays the records in table format. We can choose any of the below ‘Edit Block Modes’ based on our needs.



The below input elements are added inside the Edit Block.


  • Four Text elements with the names FirstName, LastName, Id, and AccountId are added to hold the First name, Last name, Id, and AccountId values of the Contact record.






  • In the Default Value field of the ‘AccountId’ text element, %ContextId% is added. This ensures that when a new Contact is created from the Edit Block, it will be automatically linked to the Account record, when the Omniscript is added to the Account record page.

  • From the ‘Properties’ section of the Id and AccountId elements, click Edit Properties As JSON and set the hide property to true. This ensures that the elements don’t show up in the Edit block UI. They will only be used for backend field mapping.

  • A Telephone element with the name Phone is added to hold the phone number of the Contact.


  • An Email element with the name Email is added to hold the email address of the Contact.


  • All the input elements should have the same name as the ‘fields in the Contacts array’ of the DataRaptor Extract Action to hold the corresponding values. 


Three Remote Action elements are added to the Edit Block.

1) ‘New’ Remote Action: 

This remote action is used to create a new record directly from the Edit Block.



Here, 

  • Name: Contacts-New where ‘Contacts’ is the name of the Edit Block element and ‘New’ denotes the DML operation to be performed.


  • Field Label: New, the action label that appears in the Edit Block UI. It can be set to any value (say, ‘Create’) based on the need. 


  • Remote Class: DefaultOmniScriptEditBlock. This points to the standard Edit Block-related Apex class that is included as part of the managed package (say, ‘Omnistudio’).


  • Remote Method: new. This points to the ‘new’ method in the ‘DefaultOmniScriptEditBlock’ apex class that is used to create a new record from the Edit Block.


Similarly, two more remote actions are added for ‘edit’ and ‘delete’ operations.


2) ‘Edit’ Remote Action:

This updates an existing record from the Edit Block.



  • Name: Contacts-Edit

  • Field Label: Edit

  • Remote Class: DefaultOmniScriptEditBlock 

  • Remote Method: edit. This points to the ‘edit’ method in the ‘DefaultOmniScriptEditBlock’ apex class to update an existing record from the Edit Block.


3) ‘Delete’ Remote Action:

This deletes an existing record from the Edit Block.



  • Name: Contacts-Delete

  • Field Label: Delete

  • Remote Class: DefaultOmniScriptEditBlock

  • Remote Method: delete. This points to the ‘delete’ method in the ‘DefaultOmniScriptEditBlock’ apex class to delete an existing record from the Edit Block.


NOTE: As a best practice, set the name of the ‘Remote Action’ in the format EditBlockElementName-Action instead of just the Action name. This uniquely identifies the corresponding Edit Block action and performs the related DML operations, even if there are multiple edit blocks inside an Omniscript.


Now we go back to the ‘Edit Block Properties’ section and set the ‘Max Number of Elements to Display’ and the corresponding ‘Elements Inside Edit Block’.


By default, the value inside ‘Max Number of Elements to Display’ is 3. We have modified it to ‘4’ so that four elements can be selected inside the ‘Elements Inside Edit Block’ section as shown below.


In the 'Select SObject' field of the ‘SObject Mapping’ section, select the object in which you want to perform the DML operations.

In our example, ‘Contact is the SObject.


Now click ‘Add SObject Field Mapping’ and map the edit block elements to the corresponding field in the SObject.



Optionally, the Duplicate Key checkbox can be enabled if needed. This prevents a record from being created if a matching value is found in an existing record.



Output:


Now we go to ‘Preview’ mode and enter an Account Id value in the Context ID field of the Omniscript.

It automatically fetches all the Contacts linked to the corresponding Account as shown below.



If we observe the Data JSON, it shows the Contacts array fetched from the DataRaptor Extract Action.


Create Contact:

Now if we click the New button, it shows a popup where we can enter the details of the Contact and click ‘Save’.


A new contact is created and linked with the Account record.


Also, it prevents the creation of a duplicate record based on the fields with Duplicate Key set to true. In our example, we have set the FirstName and LastName fields as the duplicate keys.


So when we enter values in these fields that match an existing record’s FirstName and LastName values, it shows the Duplicate Found error message, as shown below.


NOTE: Duplicate prevention works only during record creation in an Edit Block but not during an update operation.


Update Contact:

Now, we click the Edit option from the dropdown arrow corresponding to a record in the Edit Block.


The contact record opens in an edit screen where we can update the details and click ‘Save’.


The contact is now updated successfully.


Delete Contact:

Similarly, now we click the Delete option from the dropdown arrow corresponding to a record in the Edit Block.


A confirmation pop-up opens, as shown below.


On clicking the OK button, the record is deleted successfully.


References:


2,868 views5 comments

Recent Posts

See All
OmniStudioFactFooterBg.png
logo.png

OmniStudiofacts helps us to build a Vlocity/OmniStudio Tech Community which focuses on sharing technical skills and experience across the globe.

© 2023 by OmniStudioFacts.

bottom of page