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 - How to access ”related_id” before the relationship is saved ?

fli - Thursday, February 17, 2011 11:19 AM:

Dear Sir's.
I am out of idea's, someone please help ? 
 Case:   

 

From an Item of type “D”, a new relationship “D_C” is created by “pick related”, a related Item of type “C” gets chosen (let’s call the instance X).       Please se pic.

Problem:
When F2 is pressed for Value_id in the relationship tab.
Only Items that are related to the Item X should be shown in the SearchDialog
________
I need the related_id to query for id’s to populate the idList for an onSearchDialog event on the value_id property
I have tried accessing the D_C items related_id by XMLDom but it is empty until the relationship is saved.
var test = inArgs.itemContext.getElementsByTagName("Relationships");
alert("  test    " + test[0].childNodes[0].childNodes[12].childNodes[0].getAttribute("id"));
Thanks,
Christoffer
 

 

 

 

 


fli - Tuesday, February 22, 2011 3:48 AM:

I can't upload pic  ??



Brian - Tuesday, February 22, 2011 4:36 AM:

 This code restricts the user to the items returned by the query in "qry1"

The query is executed including all of the restrictions you need to make and  then the "Idlist" is built up with the "id's" of the Items (in this case Documents) that are returned from the search.

This idlist is then passed out of the method as an attribute of the "inargs" item that was passed in with the context item.

You should be able to substitute your query in for qry1 and this code should work for you.

 

// Called from related_id grid cell onSearchDialog event of Outoing Document

// Relationship item type.

// It is only valid for documents with the following criteria to be selected

 

// Status is "released"

// There is no "customer_response" item attached to the Document

// The flag "customer_approval_required" must be checked (true)

//

 

// Use a filtered item browser

if (!inArgs.itemContext)

    {return;}

 

// You may need to use this code to get the context item

// for your query.

// This pro_id can then be used in the qry1 to limit things to

// the set of Items you want the user to choose from.

// var itm = inArgs.itemContext;

// var pro_id = top.aras.getItemProperty(itm,"property_id");

 

 

var qry1 = this.newItem("Document", "get");

qry1.setAttribute("where", "[Document].state='Released' AND [Document].customer_approval_required='1' AND ([Document].customer_response IS NULL)");

 

var res = qry1.apply();

 

if (res.isEmpty())

{

   // if there is nothing that matches then return a string that

   // cannot possibly match a record in the database. inArgs.QryItem.item.setAttribute("idlist","00000000000000000000000000000000");

    return ("");

}

if (res.isError()) {return res;}

 

// put the Document items that match the query into a array to be

// returned to the SearchDialog.

// This method of returning a result to the SearchDialog does not

// let the user edit/change the search being used.

var idarray=new Array();

 

for (i=0;i<res.getItemCount();i++){

  var item=res.getItemByIndex(i);

  idarray[i]=item.getID();

}

 

var idlist=idarray.join(",");

inArgs.QryItem.item.setAttribute("idlist",idlist);

 

return("");

 

Hope this helps.

Brian.



fli - Tuesday, February 22, 2011 6:54 AM:

 

Hi Brian, thanks for your answer.

I don't quit get to the goal.  what does  top.aras.getItemProperty(itm,"property_id");  do?

I need the ID of [C] thus [D_C] has not been saved to the server

Datamodel:

    [D]   <----[D_C]----> [C]  <----[C_V]

rel       [D_C] prop: Value_id , Item (source = [C_V]) 

             [C]   prop: Code  ,     int

non-rel [C_V] prop: Value  ,    String   

[C_V] items are rules on a [C] item, determining which id's "Value_id" can be set to.

 

I need a Qry1 like this, I think

D_C=getItemById(inArgs

.itemSelectedID);

var qry1 = this.newItem("C_V", "get");

qry1.setAttribute("where", "[C_V].source_id= D_C.getproperty("related_id" "); 

 

Is it possible the read the cells of the grid in the tab ? if I couold read the selected code, I should be able to use this in the qurey ?

I could use some documentation on gridApplet  (gridApplet.GetCellValue)  ?

please help.

BR/ Christoffer

 



Brian - Tuesday, February 22, 2011 7:45 AM:

Hi Christoffer,

I'm confused.

I don't see how what you are describing can work.

You want to filter the [D] items based on [D_V] "rules" but you don't know what [D] is until after it is selected. SO you can't filter for it.

It sounds more like the rules should belong to [C]. When you select [C] and go to add a [C_D] relationship you lookup the [C_V] rules which gives you what you need to know to filter for [D].

As I said I'm confused and not at all sure what you are trying to do.

I think you need to look at your data model.

Cheers,

Brian.



fli - Tuesday, February 22, 2011 8:31 AM:

Hi Brian,

Sorry I had made a mistake in my Datamodel depiction. I have corrected it in the erlier post aswell.

Datamodel:

  [D]   <----[D_C]----> [C]  <----[C_V]

rel       [D_C] prop: Value_id , Item (source = [C_V]) 

             [C]   prop: Code  ,     int

non-rel [C_V] prop: Value  ,    String   

First I open a [D] item, then in the relationship tab [D_C] I "pick related" chooseing a [C] Item. now I have created a relationship Item [D_C] this [D_C] contains a Property called Value_id which is of type Item and source = [C_V].  here I should be able to only choose [C_V] Items related to the C item.

the Related [C_V]  Items are rules for the Value_id property on the [D_C] Item. 

thanks

BR/ Christoffer

 



fli - Tuesday, February 22, 2011 8:39 AM:

Hope it makes more sense now