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 - js code to add relationship in html field code of form

rrt - Monday, June 6, 2016 3:32 AM:

hiii

I am new to aras i want to show relatonship item data to grid on form so i write following code in that i write jd code to add relationship to parent item (for selected item from search dialog) but i am not able to add relationship it ives error="Insufficient permission to add item " but i gave write permission to item i Can Add and Permission peroperty of item


i code is-

<script type="text/javascript" src="../javascript/include.aspx?classes=ScriptSet2"></script>
<script type="text/javascript" src="../javascript/include.aspx?classes=XmlDocument"></script>
<script type="text/javascript" src="../javascript/include.aspx?classes=/dojo.js"
data-dojo-config="isDebug: false, parseOnLoad: false, baseUrl:'../javascript/dojo'"></script>
<script>
var gridControl = null;

var gridXML = '' +
'<table>' +
getHeaderForPackRecon() +
' <tr>' +
' <td>Test</td>' +
' <td>test2</td>' +
' </tr>' +
'</table>';
alert(gridXML);
window.addEventListener("DOMContentLoaded", function () {
clientControlsFactory.createControl("Aras.Client.Controls.Public.GridContainer", {id: "grid", connectId: "gridTD"}, function(control)

{
gridControl = grid = control;
clientControlsFactory.on(grid, {
"gridClick": onClick,
"gridKeyPress": onKeyPressed,
"gridEditCell": OnEditCell,
"gridMenuClick": onMenuClick,
"gridMenuInit": InitMenu,
"gridDoubleClick": onDoubleClick
});
gridControl.Delimeter="|";
gridControl.InitXML(gridXML);
});
});
function getHeaderForPackRecon()
{
    // Create this String <th align="c">Name</th>
    alert("test1");
    var aml = "<Item type='Symbi_PackRecons_Item' action='get' ><source_id>" + document.itemID + "</source_id></Item>";
    var res = top.aras.soapSend("ApplyItem", aml);
    var nodes = res.getResult();
    var nodesCount = nodes.childNodes.length ;
    alert(nodesCount);
    var tHeadStart = "<thead>";
    var theadEnd = "</thead>";
    var header = "";
    var colStart = "<columns>";
    var colEnd = "</columns>";
    var col = "";
    for (var i = 0; i < nodesCount; i++) {
        var node = nodes.childNodes[i];
        var relItemID = node.getAttribute("id");
        var relItem = top.aras.getItemById("Symbi_PackRecons_Item", relItemID);
        var fmItemID = top.aras.getItemProperty(relItem, "related_id");
        var fmItem = top.aras.getItemById("FM_Item", fmItemID);
        var itemNo = top.aras.getItemProperty(fmItem, "item_id");
        header = header + "<th align='c'>"+ itemNo + "</th>";
        col = col + "<column width='130' order='"+i+ "'/>" ;
    }
    var ret = tHeadStart + header + theadEnd + colStart + col + colEnd ;
    alert(ret);
    return ret;

}
function onClick(row, col)
{
return;
}
function onKeyPressed(kEv)
{
return;
}
function OnEditCell(event, row, col)
{
return;
}
function onMenuClick(menuChoice)
{
return;
}
function InitMenu(row, col)
{
return;
}
function onDoubleClick(rId)
{
return;
}

function doheader()
{
  var itemtypeID = top.aras.getItemTypeId("FM_Item");
  var param = { aras: top.aras, itemtypeID: itemtypeID, multiselect: true };
  var options = { dialogWidth: 700, dialogHeight: 450 };
 
  var results= top.aras.modalDialogHelper.show('DefaultModal', window, param,  options, 'searchDialog.html');
 
for (var i = 0; i < results.length; i++)
{
    var result = results[i];
}

var item = document.thisItem;
alert(item);
var vpack = item.newItem("Symbi_Pack_MterialRecons","add");
var fmi=item.newItem("FM_Item","get");
fmi.setProperty("id",result);
var resfm=fmi.apply();
var vATRPara = item.newItem("Symbi_PackRecons_Item","add");
vATRPara.setProperty("source_id",item.getID());
vATRPara.setProperty("related_id",result);
vATRPara.setRelatedItem(fmi);
vpack.addRelationship(vATRPara);
var res=vATRPara.apply();
alert(res);

}

function dostandarddetail()
{
  var itemtypeID = top.aras.getItemTypeId("Symbi_PackMaterialRcons_Detail");
  var param = { aras: top.aras, itemtypeID: itemtypeID, multiselect: true };
  var options = { dialogWidth: 700, dialogHeight: 450 };
  //getHeaderForPackRecon();
  var results= top.aras.modalDialogHelper.show('DefaultModal', window, param,  options, 'searchDialog.html');
 
for (var i = 0; i < results.length; i++)
{
    var result = results[i];
}
var item = document.thisItem;
alert(item);
var vpack = item.newItem("Symbi_Pack_MterialRecons","add");
var fmi=item.newItem("Symbi_PackMaterialRcons_Detail","get");
fmi.setProperty("id",result);
var resfm=fmi.apply();
var vATRPara = item.newItem("Symbi_PackRecons_Detail","add");
vATRPara.setProperty("source_id",item.getID());
vATRPara.setProperty("related_id",result);
vATRPara.setRelatedItem(fmi);
vpack.addRelationship(vATRPara);
var res=vATRPara.apply();
alert(res);

}

</script>
<div id="ButtonSection" class="logicalSubSection" align="center" style="padding-bottom: 15px;">
           <input type="button" class="btn" id="Button1" name="headerbutton" value="Add Header Item" onclick="doheader()" />
           <input type="button" class="btn" id="Button2" name="detailbutton" value="Add Standard Details" onclick="dostandarddetail()" />
            <input type="button" class="btn" id="completeButton" name="Complete" value="Add Details" onclick="" />
</div>
<table>
<tr>
<td style="width:800px; height: 800px;" valign="top" id="gridTD">
</td>
</tr>
</table>

 

this code is written in html field code of form

please help me as early as possible

 



Yoann Maingon - Saturday, June 11, 2016 11:33 AM:

Can you precise where the code crashes?

I can already see that at some point you add an Item as a relationship but you also set the source_id, you can't do both with different values.

 



rrt - Tuesday, June 14, 2016 1:51 AM:

for function doheader ()

i want to add relationship programmatically for item Symbi_Pack_MterialRecons

Symbi_PackRecons_Item is relationship item of  Symbi_Pack_MterialRecons

i want to add relationship to parent item with details get from- result variable



Yoann Maingon - Tuesday, June 14, 2016 1:07 PM:

Sorry but I don't know what you are looking for here.



edonahue - Tuesday, June 14, 2016 1:23 PM:

Hi R,

Is there a reason you cannot use the standard relationship grid in the Innovator UI? Based on your description of the use case, it sounds like you want to search for an item in a search dialog and then relate it to the current parent item. This is standard behavior in the Aras Innovator relationship grid.



rrt - Wednesday, June 15, 2016 1:20 AM:

i am actually write my code in html field code . i create grid to display data in relation tab of parent item . then i take button on grid to search item and set it to relations tab of parent item so i do code like this but i am not able to add data that i get from srarch dialog it show error of insufficient permission to perform 'add' operation but i gave all permission to parent and child item

 



edonahue - Wednesday, June 15, 2016 10:30 AM:

Hi R,

The functionality you've described is all standard behavior for relationship grids in Aras Innovator. For example:

  1. Login to an InnovatorSolutions database as admin
  2. Navigate to Design > Parts in the TOC
  3. Click the "Create a New Item" button in the toolbar.
  4. In the Part form that appears, make sure the "Pick Related" action is selected in the dropdown list on the BOM tab.
  5. Click the "New Relationship" button in the BOM tab toolbar.

This will open a Part search dialog, allowing you to choose one or more Parts you want to relate to the current parent Part item. When you choose a child Part, a new Part BOM relationship will be created in the cache. Once you save the parent Part, the new Part BOM relationship will be saved to the database.

If this is the functionality you are looking for, I recommend you use the standard relationship grid for your use case. If this is not the functionality you are looking to implement, please provide more detail on the custom behavior you are trying to achieve.



rrt - Thursday, June 16, 2016 1:19 AM:

when i add item to Pack Header then column with item code as heading is generated in grid which is on form

but i want to add item to Pack header tab from button 'Add Header Item ' which is in grid of form 

for that i written code but it not work it gives insufficient permission to perform 'add' operation

code written for add relation is as follow which is written in html field code

function doheader()
{
  var itemtypeID = top.aras.getItemTypeId("FM_Item");
  var param = { aras: top.aras, itemtypeID: itemtypeID, multiselect: true };
  var options = { dialogWidth: 700, dialogHeight: 450 };
 
  var results= top.aras.modalDialogHelper.show('DefaultModal', window, param,  options, 'searchDialog.html');
 
for (var i = 0; i < results.length; i++)
{
    var result = results[i];
}

var item = document.thisItem;
alert(item);
var vpack = item.newItem("Symbi_Pack_MterialRecons","add");
var fmi=item.newItem("FM_Item","get");
fmi.setProperty("id",result);
var resfm=fmi.apply();
var vATRPara = item.newItem("Symbi_PackRecons_Item","add");
vATRPara.setProperty("source_id",item.getID());
vATRPara.setProperty("related_id",result);
vATRPara.setRelatedItem(fmi);
vpack.addRelationship(vATRPara);
var res=vATRPara.apply();
alert(res);

}

 

 

 

 



edonahue - Thursday, June 16, 2016 9:54 AM:

Hi R,

It looks like your code is trying to create a new parent item (Symbi_Pack_MterialRecons) and add the new relationship(s) to that new parent, not the current parent item in context. Try adding the relationships to the current context item, not a new parent item:



rrt - Friday, June 17, 2016 5:34 AM:

thanks Eil Donahue its work.

now i have another problem that how to edit cell of grid that i generate on form

 



rrt - Monday, June 20, 2016 1:57 AM:

i solve edit cell problem usin following code

function onSelectCell(cell)
{
cell.setEditable(true);
return;
}

now i want to add delete button to cell of grid (gris which i generate on item form) for that i write following code

<input type="button" class="btn" id="completeButton" name="Complete" value="Delete" onclick="deleterow()" />

but it not work



edonahue - Monday, June 20, 2016 10:14 AM:

Hi R,

What code do you have in your deleterow() function? Is this button in a separate form field, or is it in the same HTML field as your custom grid?



rrt - Wednesday, June 22, 2016 6:33 AM:

hiii

i done this by taking delete button outside cell

now i have to close item and again open same item using javascript for that i write following code

var item = document.thisItem;

top.aras.uiCloseWindowEx(item.getID());
 alert(itemId);
 var newitem=item.newItem("Symbi_Pack_MterialRecons","get");
 newitem.setProperty("id",itemId);
 newitem.apply();
 top.aras.uiShowItemEx(newitem.node,undefined,true);
 return newitem;

 

or how to recall grid to update grid with changed column and row?



edonahue - Thursday, July 7, 2016 4:32 PM:

Hi R,

If you would like to refresh your grid, I would recommend reinitializing the grid control. If you close the item's window with top.aras.uiCloseWindowEx(), the parent item will no longer be in context and you will not be able to execute the rest of your method.



rrt - Friday, July 8, 2016 1:33 AM:

i want to add column to existing grid but i not get any method like addColumn() . i get method addRow() which i used successfully to add row to existing grid so how to add column to grid