How to display automatically properties from an ItemType in a Form from another ItemType, thanks to an ID

Hello,

I'm searching for a solution capable of displaying automatically properties from an ItemType in a Form from another ItemType, with an ID that creates a link between them.

I have an item linked to a form and I have a second item with some properties. I want to populate one field of the first form with the data of the second item. This field corresponds to a certain property of the first item.

To highlight my problem there is an example.

The first Item is called “student_info”. . The other properties don't matter for my problem.

  1. ItemType, Name = “student_info”

1) "student_name", DataType = "Text",

2) "student_class", DataType = "String",

3) "exam_1", DataType = "String"

4) "exam_2", DataType = "String"

5) “id”, DataType = "Item", Data Source = "student_info".

In my form “student_info”, I have a field where I want to display all the exams that a student has passed.



All the exams infos come from the second item. This ItemType is called "exam". It has 5 importants  properties :

  1. ItemType, Name = “exam”

1) "exam_name", DataType = "String",

2) "exam_descrption", DataType = "String",

3) "exam_discipline", DataType = "List", Data Source = "Discipline",

4) "exam_monitor", DataType = "List", Data Source = "Monitor",

5) “id”, DataType = "Item", Data Source = "exams".

I succeeded in changing the “id” with the “exam_name” thanks to another question on this forum !



Each student has passed a different exam. And each exam can be passed by a different student.

So, in my “student_info” form, I have created a HTML Field with an id included in a div. The id is linked to a method called “load_exam” that displays all the exams the student has passed.

BUT for the moment, I need to add manually via a Relationship that I create between the ItemType “student_info” and the ItemType “exam”. To add the exam I need to go in the edit view of the ItemType “student_info” and in the tab called “Add Exam”. And after in a dialog box I choose the right exam.

Now I want to find a solution that automatically displays the list of exams for each student. In fact if I fill the properties “exam_1” and “exam_2” with the exam name, that corresponds exactly to the “exam_name” property. I want to have the list of exams in the HTML Field of the “student_info” Form.

Thanks for reading, I hope you can understand my problem and help me to solve it !

P.S. : I can show my JavaScript code for the method “load_exam”, if you want.

Parents Reply Children
  • 0 オフライン in reply to AngelaIp

    Thanks Angelalp for you answer.

    But I already thought about nested forms and they don't match what I'm looking for ...

    More simply, I want to extract data from one or more Item from an ItemType (in my case, "exam") with the id of the Item I want. Then I want to display it in a HTML table in my "student_info" Form..

    The id is integrated in the form of "String" in my Form "student_info" but is not visible. Every "student_info" Forms have different "id" displayed as "String" so I should have as much data from "exam" in my table.

    I wish you can understand what I'm looking for.

    Thanks

  • Hi Harvey,

    ah okay. I still do not fully understand your use case, but I see that nested forms are not the right solution for you.

    As far as I understand, you are already able to display content in your html element. So your onLoad Method basically works? But why do you want to connect with ids?

    Do you have a property in your "Exam" ItemType that contains the linked student? You could than make a simple get query with a filter for the student name and render the table in the html with the onLoad method. 

    var exam = inn.newItem("Exam","get");
    exam .setProperty("student_name", "Kojak"); 
    exam .setAttribute("select","exam_name, result");
    exam = exam .apply();
    for (var i = 0; i < exam .getItemCount(); i++)
    {
      // build table in html element
    }

  • 0 オフライン in reply to AngelaIp

    Hi Angela

    Thanks to show some interest for my case. And sorry for my late answer.

    So your onLoad Method basically works?

    Yes, the method works fine. But it only works when, on the view form, I go on Tab RelationShip and add the relationship manually. I've create a relationship between "student_info" and "exam" Itemtype. Actually this is the only solution i've found to display the "exam" properties in the "student_info" Form.

    But why do you want to connect with ids?

    I want to automate what I explained above.. This is why i want to use id's. In my "student_info" Form, i've Text Field Type. In these Text Field, I have the id of the "exam" ItemType. I don't need to fiil each Text Field because their content come from an imported excel file. 

    In other words, I'm searching for an automatic way to search through all Items from an ItemType, the Item which has the same id of the content of a Text Field in a Form. Then, when this Item is selected, I want to display it in this same form.

    I hope you can understand my needs now.

  • Hi Harvey,

    I also have some issues understanding your setup (why do you want to link student_info and exams via a string property? Why not at least use an "Item" property or just use what you are currently using, i.e. explicit relationship; just sounds much cleaner to me to have an explicit link between items in Aras rather than some string), but if I understand you correctly, Angela's second suggestion should still work. Assuming you have an Innovator object called "inn" and a method that gets the Exam-ID-property on student_info:

    var examId = getTheStringPropertyThatStoresTheIdOfTheExam();
    var examItem = inn.newItem("Exam", "get");
    examItem.setID(examId);
    examItem = examItem.apply();

    Then you have the relevant Exam Item and can fill your HTML-table with the properties of that item.

    If you use an "Item"-property on "student_info" that actually links the Item "student_info" to the item "Exam", you can also use foreign properties out-of-the-box, no need to code anything. If you google "Aras Foreign Properties" you will find some (older but at their core still valid) blog posts explaining how they work.

    Cheers,

    C

  • 0 オフライン in reply to cogres

    Thanks a lot, your answer about foreign properties gave me an idea.

    So now, I'm able to display the data I want in an HTML table in my "student_info" form. 

    But the purpose is to automate this process, To achieve this, I need to find a method to do a "copy-paste" the value from a text field to an item field. Whose are in the same form. I attach a picture to illustrate my point. In my text field, I have a string, which correspond to the ID of the item. I see that you can write ID in it when the item is lock. and it's a link towards the related item when it's unlocked.

    Can you rovide me some advices to write the good method to do this ? 

    I hope your can understand my need.

    Thanks

  • Hi Harvey,

    How do you fill the property fields "ID Item 1" and "ID Item 2"? THAT is where you should populate the Item property fields, not in an extra step at a later stage. You said 'in my “student_info” form, I have created an HTML Field with an id included in a div' - instead of filling that node in HTML programmatically, simply fill the Item properties programmatically.
    The Item property fields are also simply string fields with some extra logic added on top, so it is not at all any more difficult populating those than any other fields.
    How to exactly implement this logic depends on where you want it fired/where the form itself is populated, but you will simply set those Item properties the same way you would set any other property, i.e. with item.setProperty("name_of_exam_item_property", examId);.
    If you could provide us with snippets of the code used to fill the form, I could give you more detailed advice.

    Hope this helps,

    C

  • 0 オフライン in reply to cogres

    Hello C,

    How do you fill the property fields "ID Item 1" and "ID Item 2"?

    It's comes from an imported excel file. Where the data source comes from the value of the excel sheet. It's programally fiiled.

    You said 'in my “student_info” form, I have created an HTML Field with an id included in a div'

    I've done this for multiple properties. Especially the text and dropdown flieds. In invisible I have field to recover data from the imported excel file. Then I display all these data in HTML fields as visible in my form. In HTML i know how to include an id in the tag to apply the document.getElementById("") an to display the value. But I want to know how to do this for an item fiel. Should I try the document.getElementsByName('') method ?

    For the moment I have this code to try to "copy-paste" my deta from te text field to the item field. It's from a method where the envent is "OnLoad" :

    var exam1_id = document.getElementsByName('_exam1_id')[1].value; //get the value of my text field

    var examitem = document.getElementsByName('_exam1'); //get the item field to fill

    examitem.value = exam1_id;

    But this code seems to not work. I will try to implement your item.setProperty("name_of_exam_item_property", examId); code line.

    I'm new to Javascript and I'm learning every day. There is a lot of methods and thing to learn.

    Thanks for helping me.

  • Hi Harvey,

    ah I see! The Aras JS method you are looking for is window.handleItemChange(nameOfProperty, valueForProperty). But beware that changing item properties in JavaScript can be tricky due to potentially inconsistent lock-status of the item, for example. You'll have to test around a little to make sure it does what you want.
    I still believe that instead of doing this you should hook the logic into the import of the Excel sheet. In the program that performs the Excel import, you should try to set the Item property right then, if that's at all possible.

    If you have any more questions, let us know :). JavaScript can be a little fickle sometimes, so if you're just starting out, be prepared to lose a good part of your brain cells to it Smiley.

    Cheers,

    C

  • 0 オフライン in reply to cogres
    I still believe that instead of doing this you should hook the logic into the import of the Excel sheet. In the program that performs the Excel import, you should try to set the Item property right then, if that's at all possible.

    I first try this way. It works as I want. But, I bring some modification to my excel import file. In the culumn I fill manually the source ID of the Exam Item I want to display.

    I found this Source ID when I right click on the item and choose Properties. This Source ID is given randomly when i've imported my excel file list of exams. Aside, I've success to modify the Keyned Name Order to display a property as ID (not the source id i've mentionned). 

    Then when I import the excel file it works correctly, but with the source id and I want to do it whith the id I modified. Do you know if there is any solution to achieve this ?

    The Aras JS method you are looking for is window.handleItemChange(nameOfProperty, valueForProperty). But beware that changing item properties in JavaScript can be tricky due to potentially inconsistent lock-status of the item, for example. You'll have to test around a little to make sure it does what you want.

    i will try this way next week, i will let you know if it works or not. Thanks for giving me the right method !

    And shure, I will not hesitate to ask you or the community if I have other question ! It's good to know that I can count on you ! Slight smile

    Thanks a lot for all  your help !

    Cheers