AnsweredAssumed Answered

Setting Field as selected in script?

Question asked by sk on Aug 5, 2011
Latest reply on Aug 5, 2011 by sk

Title

Setting Field as selected in script?

Post

Hi All,

I'm trying to set a calculated field to "1" if it is the only related record.

I have a raw materials table, suppliers table and a join table between them of rawmtrlsupplier.
While in raw materials table, user can add one or more suppliers for a particular raw material, and see this in a related portal. In the portal of suppliers I have a field "rawmtrls_RAWMTRLSUPPLIER:: _MainSupplierID" with a checkbox set that has a value list of "1". It also has a button applied to it as shown below:

Scripts: Set Default Supplier
Set Error Capture [ On ]
Set Field [ RawMtrls::_kf_DefaultSupplierID; rawmtrls_rawmtrlsupplier_SUPPLIER::__kp_SupplierID ]
Refresh Window

It also has a calculation assigned to it which is:

If (rawmtrls_rawmtrlsupplier_SUPPLIER::__kp_SupplierID = RawMtrls::_kf_DefaultSupplierID; 1; 0).
This lets me set the RawMtrls _kf_DefaultSupplierID with the appropriate Supplier ID, so that I can use it for a script to find all of the raw materials related to supplier, so that a user can go to a pick window and add the items they want on a PO for that supplier. 

How do I enable the checkbox being automatically selected when there is only one supplier in the portal?

Right now the user can add a new supplier but if it is the only one in the portal then they also have to click on the field to select it as the main supplier. Seems counter intuitive to have to do this extra step if there is only one supplier in the portal.

I have tried scripting in a find to the RAWMTRLSUPPLIER to see if the particular raw material only has one supplier and then set the rawmtrls_RAWMTRLSUPPLIER:: _MainSupplierID to have a value of 1, but because it is a calculation field, I can't modify it.

What is a good way to approach this?

Outcomes