priority-web-sdk: fieldUpdate for choose field fai

2019-08-20 11:53发布

问题:

My form contains a field with drop down values (the values came from the choose function) and when I am trying to update the field (with fieldUpdate) in the second time I always get the following error: "A record with the same value already exists in the screen", What is the correct order of actions that need to be done in order to achieve the right behaviour? This is my attempt to achieve that:

await actions.loginTest();
const form = await actions.priority.formStart(this.formName, 
this.onShowMessgeFunc, this.onUpdateFieldsFunc);
_formInstance = form;
const rows = await form.getRows(1);
console.log("parent form rows", rows);
await _formInstance.setActiveRow(1);
form.choose("CUSTNAME", '').then(options => {
let custOptions = options.SearchLine.map(x => {return {label:x.retval + " - 
" + x.string1, value: x.retval }});     
}).catch((err) => {
console.log("CHOOSE ERROR", err);
})    

When I select a value from the drop-down, those are my actions:

await _formInstance.fieldUpdate("CUSTNAME", data.value);
await _formInstance.saveRow(1);
const rows = await _formInstance.getRows(1);
console.log("rows", rows);

In the first time it work's great, but when I select a different value for the second time I get an error that say that this value already exists (it's like it think that I am trying to update the value but I don't, I just want to get the values of other fields that return as a result of the field trigger when I leave the field in Priority). I don't have any purpose to change values, just getting information on other fields and data from sub-forms.

回答1:

I don't have any purpose to change values, just getting information on other fields and data from sub-forms.

In order to achieve your purpose you could choose one of the following flows, that should work:

  1. Recommended: Use getRows() after you have setSearchFilter() in order to retrieve the row you're interested in including its fields. Then easily setActiveRow() with its index to startSubForm(). You could always use clearRows() to clear the current rows and retrieve others.

    Example:

    const form = await actions.priority.formStart(this.formName, 
                 this.onShowMessgeFunc, this.onUpdateFieldsFunc);
    const filter = {
      QueryValues:
      [{
        field: 'CUSTNAME',
       fromval: value,
       op: '='
     }]
    }
    await form.setSearchFilter(filter)
    const rows = await form.getRows(1);
    console.log("parent form rows", rows);
    await form.setActiveRow(1);
    await form.startSubForm(1);
    
  2. Perform the 'update' on a newRow() without calling getRows(). Then saveRow() and startSubForm() to get the information you need. Do this for each record you trying to retrieve its data.

    Explanation: When calling getRows() you retrieve some rows. Then you cannot update a key field with a value that already exists in the retrieved rows otherwise you get that error.