Reputation: 1187
Is there a way to filter the Items that are listed in a field by the selected Purchase Order (transaction), ie user selects a purchase order, that then populates the Item field with a list of items on that purchase order?
Sorry if this is a really easy question, but I have searched all over the place, and I can't find exactly this scenario. Can't find it in the documentation, either. I'll keep trying, but if anyone knows off-hand, it would be much appreciated!
Upvotes: 0
Views: 2186
Reputation: 227
All of this can be done from clientscript on fieldChanged
event of PO field. First, apply search on PO and get all the sublist item list and then remove all select options of item field and then add the PO's sublist item list on this field.
function fieldChanged(context){
var currRec = context.currentRecord;
// search on PO to get sublist items
var itemSearch = search.create({
type: 'purchaseorder',
filter: ['internalid', 'is', '<your PO id>'],
columns: ['item']
}).run().getRange(0,100);
var poItemList = [];
itemSearch.forEach(function(result){
if (result.getValue({name: 'item'})) {
poItemList.push = { value: result.getValue({name: 'item'}), text: result.getText({name: 'item'})};
}
})
//remove all options of item field
var itemField = currRec.getField({fieldId: '<your custom field>'});
itemField.removeSelectOption({value: null}) //this removes all options
//add sublist items in item field options
poItemList.forEach(function(item){
itemField.addSelectOption(item);
})}
Hope this helps!!
Upvotes: 1
Reputation: 43
I know this is very old, but I think a more robust solution would be using the saved search filter available on the custom form.
From the admin center --> Customization --> Forms --> Transaction Forms --> "Your Form" --> Edit
Under the sublist fields tab is a dropdown menu of item searches. You would just select a search that limits the drop down based on your needs.
Upvotes: 0
Reputation: 3029
It's possible using Suitescript.
You need to dynamically insert a custom select field to the form on beforeLoad
using a User Event script, lets call it custpage_mycustomfield
.
Then you need a clientscript that populates the list of items on custpage_mycustomfield
, this needs to happen after the PO field has been changed. You can run a search or load the record to get the line items.
The data you enter in custpage_mycustomfield
won't be saved, so if you want to preserve it you need to do the following:
Create a custom field using the UI that is of type of List/Record >
Item, lets call it custbody_mypermanentfield
Set a clientscript function to run on saveRecord
that will copy the
value selected from custpage_mycustomfield
to custbody_mypermanentfield
.
Upvotes: 1