Use “Save as” functionality on readonly fields => change them to ‘null’
Hello Guys,
Can you help how can I solve the following issue:
When I use the “Save As” on an item (Shipping Kit) I want to change some fields to ‘null’. (in the new Item)
But those fields what I would like to change are readonly so I am not able to modify them.
(It is possible to solve it with privileges, but it not a solution for me because I don’t want to let ‘anybody’ to modify those fields. I just want to copy them with null values.)
But then a request came to change some readonly fields during the SaveAs to null…
Here is what I’ve tried but of course it is not worked….as It was written in the documentation as well:
if(att == 2000018787){
//newObj.setValue(att, "");
//OR
//ICell tmpCell = newObj.getCell(att);
//tmpCell .setValue(null);
}
Here is the full do Action method, just in case.
(There is an oracle table that stands for to which fields should copy over when we use “save as” => excludeATT , requiredATT strings… stands for this)
public EventActionResult doAction(IAgileSession session, INode pxNode, IEventInfo req) { CMProperties Props = CMProperties.getInstance(); String readOnlyATT = "readOnlyATT = "; String excludeATT = "excludeATT = "; String requiredATT = "requiredATT = "; String defaultValueATT = "defaultValueATT = "; String errorMsg = ""; try { if (req instanceof ISaveAsEventInfo) { ISaveAsEventInfo f = (ISaveAsEventInfo) req; Map map = new HashMap(); IItem newObj = (IItem)session.getObject(ItemConstants.CLASS_PART, f.getNewNumber()); //clear attachment table try{ ITable attachmentTable = newObj.getTable(ItemConstants.TABLE_ATTACHMENTS); attachmentTable.clear(); }catch(Exception ex){ errorMsg = "Failed to remove attachments. "; errorMsg += "Failed Reason : " + ex.toString() + ex.getCause().toString(); } //clear not included fields String partType = null; ICell cell = null; cell = newObj.getCell(ItemConstants.ATT_TITLE_BLOCK_PART_TYPE); partType = cell.getValue().toString(); if (partType == null){ return new EventActionResult( req, new ActionResult( ActionResult.STRING, "Error: Empty part type!") ); }else{ SaveAsDAO dao = new SaveAsDAO(); SaveAsService service = new SaveAsService(); //start update field visibility on nird_apd_incl_attr int partTypeID = (Integer) newObj.getAgileClass().getId(); service.checkPartAttributesVisibilityChange(partTypeID); //end update field visibility on nird_apd_incl_attr //start exclude part attributes for Agile Save As ArrayList<Map> attributeList = dao.getExcludedAttributes(partType); for(int i=0; i<attributeList.size(); i++){ boolean isCompulsoryATT = false; Map<String, Object> attribute = attributeList.get(i); int att = (Integer) attribute.get("ATTRIBUTE"); // Get the Parts class IAgileClass partClass = newObj.getAgileClass(); // Get the "Page Two.List01" attribute IAttribute attr = partClass.getAttribute(att); //Check if attribute is required if(service.isAttributeRequired(attr)){ requiredATT += att + ", "; continue; } //NOT WORKING BECAUSE THE FIELD IS READ ONLY if(att == 2000018787){ // newObj.setValue(att, ""); //OR // ICell tmpCell = newObj.getCell(att); // tmpCell .setValue(null); } //Check if the attribute is read-only, if yes then skip try { //logger.error("Get read-only cell "); ICell readOnlyCell = newObj.getCell(att); if (readOnlyCell.isReadOnly()) { readOnlyATT += att + ", "; logger.error("readOnlyATT : " + readOnlyATT); continue; } } catch (APIException ex) { logger.error("APIException = " + ex.toString() + ex.getCause().toString()); System.out.println(ex); } //add attribute with it's value as null to map excludeATT += att + ", "; map.put(att, null); } //set attributes to null newObj.setValues(map); } } }// end try .... Thanks, Feri
Hi Feri,
Assign Role having Discover Privilege,Read Privilege ,Modify Privilege on Attributes(Inclusive of all Attributes which needs to be modified) and assign it to PX. In this way, Other users cannot Modify the attributes but attributes can be updated via PX.
Thanks,
Karthik