Forum Discussion

mouad's avatar
mouad
Creator I
6 years ago

saving an item programatically after locking it

Hello All,

I have created an itemtype "ItemOne" with Form that conyain a field "fieldTest".

What i want to do is filling the field when the ticket is locked.

I have created a form event method and assign it to the form with event onFormPopulated:

var lock = document.thisItem.getProperty("locked_by_id", "");

if (lock =='' ){

var field =getFieldByName("fieldTest");

field.getElementsByTagName("input")[0].disabled = false;
field.getElementsByTagName("input")[0].readOnly = false;

}
else {

var fields =getFieldByName("fieldTest");
fields.getElementsByTagName("input")[0].disabled = true;

}
}

The method above allow to fill the fieldTest if the item is locked (value of locked-by-id is emty) otherwise the fiield wiill be disabled.
So when the item is locked, we can fill the fieldTest but the button save is disabled and when i unlock the item and save , Aras considers that the field is not filled, saves the item and leaves the fieldTest empty.

Is there any way please on how to achieve this ?

4 Replies

  • Hello,

    Could you clarify what the fieldTest field is intended to represent? If this is intended to be linked to a property on the item, you can do this by setting the Data Source of the field through the form editor. If this is intended to represent data that isn't linked to a specific property on the item, you'll need to also handle loading in the appropriate data in an onFormPopulated event.

    Chris


    Christopher Gillis

    Aras Labs Software Engineer

    • mouad's avatar
      mouad
      Creator I

      Thanks Chris for your reply,

      can you please share an example about handle the loading data ?

      Note that the goal is to fill the fieldTest that is not linked to a specific preperty when the item is locked .

      • christopher_gillis's avatar
        christopher_gillis
        Community Manager

        Hi mouad,

        You can fill the value of these fields by getting the input element and setting the value. This is a very similar process to what you're already using to enable/disable the fields.

        fields.getElementsByTagName("input")[0].value = "Your value";

        Additionally, would you be able to clarify more about the exact use case for this field? Depending on what you're trying to do, I may be able to suggest a better alternative than manually handling all of the functionality behind this field.

        Chris