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 - Form - Reading a property of an entry made into the form

KamranAftab - Wednesday, November 20, 2013 11:04 AM:

Hi All, my first post here. I'm new to aras and trying to figure out things.

I have added two fields to a form, a "Part Number" and a "Catalog Number". I have added a property "catalog_number" to the OOTB Part object.  In this new form, when the part number is entered by the user, I want to pull the catalog number associated to that part pulled into the catalog number field automatically. 

So, for example:

Part Number:  1234    Catalog Number: abcd

When the form is pulled by the item is is associated with, and the user picks part 1234 for the "Part Number" box, I want the "Catalog Number" box to pull the value "abcd" automatically.

Thanks for all your help.

Kamran

 



Amit Nawale - Friday, November 22, 2013 3:09 AM:

Hi Kamran,

You need to write method and assign to field change event on Par Number.

To Create method use following steps.

  1. Go TOC-->administrator --> method.
  2. create new method.
  3. select method type as java script.
  4. write following code in code area.
  5. check syntax.
  6. give name to method and save it.

code.

var parNumber=this.value;

 var  CatalogNumber = 0;

write you logic to get associate Catalog Number from parNumber in CatalogNumber  variable.

use below code to set catalog number on form.

window.handleItemChange("property",value).

eg.

window.handleItemChange("CatalogNumber",CatalogNumber  ).

return this.


To Create Field event use below steps.

  1. open part form.
  2. lock it and click on part number field.
  3. click on filed event tab.
  4. create on create new button.
  5. select action as pick related.
  6. select method that you are created above.
  7. assign even as "onchange" Event.
  8. save form and unlock it.
  9. Clear browser histroy.
  10. check the result.



DavidSpackman - Monday, November 25, 2013 2:25 AM:

Hi Kamran,

It sounds like you want to use the Foreign Data Type Property

I think you have started some of these steps, but I will list from the start

  • Create your new itemtype
  • Add a new property for your part item (Data Type = Item & Data Source = Part)
    • Note: This field will display the Keyed Name for the item
  • Add a new property for your part catalog number (Data Type = Foreign)
    • When you press tab a new dialog will open called Foreign Property Selection Tree
    • From the list, choose the property name that you gave to your part
    • Expand the tree and choose the property you wish to display (In your case catalog number)
  • Save the Item Type
    • Add permissions, TOC View, etc
  • Create the Form

The field will display/update after you have saved the itemtype.

There is more help in Just Ask Innovator (Under the Help Tab in Aras). See Foreign Data Type



KamranAftab - Monday, November 25, 2013 9:08 AM:

Hi Amit,

Thanks a lot for your reply. I tried this approach and spent an entire day, but was not able to make the methods work. They just wont return anything. So for example:

var myInnov = new Innovator();

var part = myInnov.newItem("test","get");  // This never returns an error, so I don't know if it works or not

Also tried:

var qryItem = myInnov.getItemById("Part","test");

Anything I try to read the value of the property returns an error saying "object required" or something with "null"

var catalogNumber = qryItem.getProperty("catalog_number");

var part.getProperty("catalog_number");

I do have another solution though, based on the subsequent reply.



KamranAftab - Monday, November 25, 2013 9:11 AM:

Hi David,

Great solution. This is so much better than writing custom code. A lot more elegant. 

My only beef now is that one has to save the item before the values show up. Is there a way to get the values updated as one picks the part item in the first box? I suppose this will have to involve writing a few lines of method code.

 

Thanks a lot for taking the time to respond!

 

Kamran



Amit Nawale - Tuesday, November 26, 2013 12:54 AM:

Hi Kamran,

use can use following code for reference.

var inn=this.getInnovator();

//specify Itemtype Name and Action

var itm=inn.newItem("Test","get");

//specify property name and its value like below

itm.setProperty("name","tstpart");

//apply the item to get result from server.

itm=itm.apply();

//get Property from result item

var catLogNumber=itm.getProperty("catlogNumber");

return this;Innovator();

you can use alert() to check value of catlog number like

alert(catLogNumber) before return this.

//here you have to specify Item Type Name and ID of its instance

var qryItem = inn.getItemById("Part","id");

 

 



DavidSpackman - Monday, November 25, 2013 6:33 PM:

Hi Kamran,

 

Yes you would need to create a custom method to do this.

It would be a javascript method that is run as a field event on the part number field in the form (See Just Ask Innovator under Forms/Events)

 

I can provide some example code, however I wouldn't suggest updating this way. 

If you update the part catalog number in the future, the other item type that referenced the catalog number is now out of date.



KamranAftab - Tuesday, November 26, 2013 10:04 AM:

Hi David,

I'm not updating the part attributes in the custom item, only populating the part attribute fields in that form. So my custom item form says:

Part: 

Name:

Catalog Number:

When the user picks the part in the form, the Catalog Number and Name fields get filled automatically. The field is disabled, so it cannot be modified there. 

I understand I will have to add event code to the "Part" field ... onChange. However, I haven't been able find any help on methods, especially javascript calls. I don't find  "Ask Innovator" of much help. Where does one find help on the Javascript methods that can be employed? I have not found that in the API reference either.

Thanks,

Kamran



DavidSpackman - Wednesday, November 27, 2013 3:05 AM:

Hi Kamran,

What happens when/if the part item is updated? The custom item information might now be out of date.

 

Unfortunately there is a lack on information on some aspects of creating custom methods.

  • Have you read the programmers guide on the website? http://www.aras.com/support/documentation/
  • You can also find a lot of information by looking at existing methods in the out of the box Aras install, as well as code in the demo databases and other Aras projects. http://www.aras.com/projects/.
    • When searching Aras methods, one of the best methods taught to me was to edit the method itemtype to unhide the method code field, combine this with wildcard searches and filtering the method type to look for examples of code usage

  • There is a lot of javascript code in the Aras server install folder in /Innovator/Client, a good notepad search can turn up a lot of information if you know what you're looking for.
  • The forums also have a lot of good code examples. (Use google to filter your searches though 
  • If you are on subscription you have access to Aras support for any questions you have, as well as additional training material.

Here is my take on what you wanted

 

Possible events

 

  • onBlur – runs when a user leaves field. 
  • onFocus – runs when the cursor is moved into the field. 
  • onChange – runs when the value of the field is changed. 
  • onClick – runs when the user mouse clicks in the field. 
  • OnDblClick – runs when the user double clicks the mouse in the field. 
  • onSelect – runs when a user selects text in a field. 

 

 

Code

//debugger;

var thisItem = document.thisItem;

var inn = thisItem.newInnovator();

 

//Get the value in the field

//Returns the id of the item

var partnumber = thisItem.getProperty("part_number");

 

//Get the Part Item and the name of the part

var PartItem = inn.getItemById("Part", partnumber);

var PartName = PartItem.getProperty("name");

 

//Update the field

handleItemChange("part_name_other", PartName);