This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Concatenate three property values into another property of the same Item

Nian - Thursday, July 7, 2011 4:54 AM:

Hi there

I am new to Aras as well as coding, but I have to solve this issue...

This is the scenario:  In one ItemType (LMT_Item), I have the following properties...

  1. project_number = This is a Foreign Data Type, derived from a property from an Item in the list of projects, which you select from the Form.
  2. gen_number  = Unique generated number from a sequence.
  3. ext_list = Its value is redived from a list, which you select from the Form.

I need to concatenate these three values into another property called "lmt_number", separated by a "-" character.

I managed to get this done through the form, by means of a new method in a Form Event on both onLoad and onMouseMove, but does not fill in properties 1 and 2 upon creation, nor does it change property 1 if you edit the Item Instance.  Only if you edit it again, would it update property 2 and apply it to the concatenation.  See the code for this solution below...

I do, however feel that this should not be done on the Form side, but rather on the Item Type as eiter a Client or Server event, so this process can happen automatically in the background.

My problem is that I just cannot seem to get the coding right for this solution (possible, mainly because of my lack of coding experience).

Please, if anyone would be so kind as to help me out (possibly with a sample code), I would be very grateful!

Thank you

Nian

The Form code...:

// Get a handle to the field object.
// The ID for the field is the property name with _system suffix.
var field = document.getElementById("lmt_number_system");

// Get other field values
var proj = document.getElementById("project_no_system").value;
var uniq = document.getElementById("gen_number_system").value;
var ext = document.getElementById("ext_list_system").value;

// Add values into field
field.value = proj + "-" + uniq + "-" + ext;
document.thisItem.setProperty("lmt_number", field.value);

// This will update the client cache with the new value.
handleItemChange("lmt_number", field.value);

 



Brian - Thursday, July 7, 2011 11:50 PM:

Hi Nian,

I would probably be using an onBeforeAdd and onBeforeUpdate server method for the item.

This fires just before the Item is saved.

In c sharp it should look like:

string proj = this.getProperty("proj_no_system");
string uniq = this.getProperty("gen_no_system);
string ext = this.getProperty("ext_list_system);
string concatVal = proj + "-" + uniq + "-" + ext;
this.setProperty("lmt_number",concatVal);
return this;

It reads the values, concatenates them and sets the value in the DOM which is then sent to the server and saved.

Hope this helps,

Brian.



Nian - Friday, July 8, 2011 3:06 AM:

Hi Brian

Thanx for the quick help!  I had everything right, except for the "return this"-part.

There was one error on your code though...  The property name should not have the "_system" suffix added to it.  It seems as if you only need this when you are reading properties through a form (as my first attempt).

Thanx again for your help.  You have no idea how much time I've wasted on this issue!

Wach this space.  There will probably be many more questions to come...

Cheers

Nian



Nian - Monday, July 11, 2011 11:04 AM:

Hi Bryan

I thought I had it right, but I still have the second problem I mentioned before: "...but does not fill in properties 1 and 2 upon creation, nor does it change property 1 if you edit the Item Instance.  Only if you edit it again, would it update property 2 and apply it to the concatenation."

The "onBeforeUpdate" seems to do its trick, but not the "onBeforeAdd".  It feels as if this method should only run after the "proj" and "uniq" properties are generated.  Or maybe something should trigger these properties to populate before the method runs (like on a form/field event).

Any suggestions here?

Thank you

Nian



Brian - Tuesday, July 12, 2011 6:52 AM:

Hi Nian,

See this post:

http://www.aras.comhttp://www.aras.com/Community/forums/t/1700.aspx

And you only actually want to call the method on "onBeforeAdd" unless the user can change some of the values on edit.

Cheers,

Brian.