How to edit records from a capture link.

How to edit records from a capture link.

In this article, see how to create a binding to edit a record from a grid used in a capture binding.
We cannot use the edit link in this case, as the edit button will not be available when we access the grid to capture a value.

Taking into account that the capture link is already configured, follow the steps below to configure the grid (used in the capture) and the form (used in editing the record)

Grid Application

In the grid application, we will create a link to edit the record using the macro sc_link.

Adding the editing image to the application

First we must add the image that will be used in the grid to symbolize the edit button.
Why add images in the Application's Extra Images option?
We must always add images that will be used in codes. This ensures that when publishing, the image will be uploaded and is also stored in the same directory, both in the publication and in the development environment, ensuring that the image is not broken after publication.

1 - In the side menu in the grid application, go to: Application > Settings



2 - In the option Application Images click on the icon to add an image:  

3 - In the image manager, click Project > Icons



4 - Click File > Upload and select the icon that will represent the edit record button.



The added images will be stored in this directory ../_lib/img/
When uploading, some prefixes are added to the image name, according to the directory where it will be stored.
Images can be saved in the following directories: Public, Project and User.
  • Public - sys__NM__
  • Project - grp__NM__
  • User - usr__NM__

Within each directory there are some sub-directories: background images, button images, general images, icons and menu images.

  • Background images - bg__NM__
  • Button images - btn__NM__
  • General images - img__NM__
  • Icons - ico__NM__
  • Menu images - menu_img__NM__
When saving an image with the name contract.png in the Project > Icons directory, as in the tutorial, the image name should look like this:

grp__NM__ico__NM__contract.png

Creating a virtual field

We must create a camp to receive the redirect link to the form.

1 - Click on the New Field option



2 - Define the field name which must be of type text.



3 - Remove the label from the field and set the title alignment as in the image below.



onScriptInit Event

In this event, we will reset the value of the global variable that will be passed to the form.
This way, we guarantee that the variable will always have no value if we click on the record that will be edited.



Code used in the event
  1. // Resets the global variable that will be passed as a parameter to the form.
  2. sc_reset_global([id_customer]);

onRecord Event

In the onRecord event, we will define the link using the sc_link macro and the image that will be displayed in the field created earlier, using the img tag.
For more details on the sc_link macro, access our documentation.


Code used in the event

The images inserted in the Application Extra Images option will be stored in the ../scriptcase/app/projeto_name/_lib/img directory.
Thus, to assign an image to a field, we must use the img tag informing the image directory and the name like this:
../_lib/img/grp__NM__ico__NM__contract.png

  1. // Defines the image that will represent the button to edit the record.
  2. {link} = '<img src="../_lib/img/grp__NM__ico__NM__contract.png">';

  3. /Remembering that the id_customer parameter will be received as a global variable in the form.
  4. sc_link (link, form_customers.php, id_customer = {customerid}, "Click here to edit record""_self");

Application Form

In the form application, we will add a global variable in the application's SQL in addition to a validation in the onApplicationInit event.

SQL Configuration

In the SQL settings of the form, which will be called to edit the record, add a global variable. In the example, we are using the variable [where]


onApplicationInit Event

In this event, which is executed before the application's SQL assembly, the value of the variable [where] must be defined, so that the form is executed correctly.

It is necessary to validate whether the variable [id_customer], passed as a parameter in the sc_link macro in the grid's onRecord event, has a value.

There will be two possible situations:
  1. In case the variable [id_customer] is empty - In this situation, the variable [where] must receive an empty sing. This way, the form will return all records normally.
  1. If the variable [id_customer] has a value - This implies that some record was selected in the grid to be edited. Thus, the variable [where] must receive the query that will display only the record selected in the query. Remembering that we must use a key field to create this link.


Código utilizado no evento
  1. // Validates if the parameter passed by the query has a value
  2. if ( empty( [id_customer] )) {
  3. // If [id_customer] is empty, the variable [where] must receive an empty string, causing the form to display all its records.
  4. [where] = '';
  5. // If [id_customer] has a value, it enters else
  6. else {
  7. // In this case, the variable [where] will receive the query to display only the record selected in the grid.
  8. [where] = "customerid = '[id_customer]' ";
  9. }

Grid in operation

Grid application, opened from a capture link with the record edit button.


    • Related Articles

    • How to create an edit link

      Edit Link: Used to edit grid records through a Form. In the generated grid a link will be displayed on each row for editing the record. By clicking on the link, the form of the selected record can be displayed in various ways (in an iframe, in a ...
    • How to create a capture link

      Capture Link: Used for the grid filter form, it imports data from another grid into the filter form field. Selecting the capture link type will display a list of fields in the filter form so that you select the field that will receive the data ...
    • Express Edit

      One of the features available in ScriptCase is the express edit. This option allows you to make some changes in several applications at the same time, significantly reducing the time to make these changes. In the express edition it is possible to ...
    • Change the charset to view the records.

      When an error appears in the charset of the special characters as in the image below: This happens when the database charset and the script case charset are not the same but we can no longer edit it in the database. We use the following code in the ...
    • Limit number of records to be displayed in the Grid

      To limit the number of records to be displayed, we will use the Limit function within the query where they bring the data of a certain table. For example in this way: Then only 5 records are shown: