简体   繁体   中英

saved search set value

I cored a saved search, and when I logdebug the results appear as I want. but when I try to set the value to the destination field, there is no response with any results.

if(cust){
                var custSave = search.create({
                type: "customrecord_me_customer_sales_person",
                 filters:
                   [
                    ["custrecord_me_customer_name","is",cust],
                   ],
                columns:
                [
                      search.createColumn({name: "custrecord_me_customer_name", label: "ME - Customer Name"}),
                      search.createColumn({
                         name: "custrecord_me_join_sales_person",
                         sort: search.Sort.ASC,
                         label: "ME - Join Customer Sales Person"
                      })
                   ]
                });
                log.debug(
            "sales person"+JSON.stringify(custSave)
                );
                var custSR = custSave.run().getRange(0, 1000);
                        var cust = custSR[0].getText("custrecord_me_join_sales_person");//the result I want in
                        log.debug(
                        "join customer sales person"+JSON.stringify(cust)
                        );
                        return true;
                    
                if (cust.hasOwnProperty('custrecord_me_join_sales_person')){
                var salesPerson = cust.getValue('custrecord_me_join_sales_person')[0].value;
                //var salesPerson = currentRecord.getValue({"custrecord_me_join_sales_person"});
                
                currentRecord.setValue({ fieldId: 'custbody_me_field_deposit_salesman', value: salesPerson });
                        }
                else{
                    currentRecord.setValue({ fieldId: 'custbody_me_field_deposit_salesman', value: null });
                    }
                            
        }              
    }           
}

    return {
        fieldChanged: fieldChanged
    }

is there an error in my script (there is no error notification). thanks for answering

Your code is so badly indented that you can't read it properly, so you didn't see you exit your code before setting the value. Here a version of your code somewhat indented:

if (cust) {
  var custSave = search.create({
    type: "customrecord_me_customer_sales_person",
     filters: [
      ["custrecord_me_customer_name","is", cust],
    ],
    columns: [
      search.createColumn({name: "custrecord_me_customer_name", label: "ME - Customer Name"}),
      search.createColumn({
        name: "custrecord_me_join_sales_person",
        sort: search.Sort.ASC,
        label: "ME - Join Customer Sales Person"
      })
     ]
  });
  log.debug("sales person" + JSON.stringify(custSave));
  var custSR = custSave.run().getRange(0, 1000);
  //the result I want in
  var cust = custSR[0].getText("custrecord_me_join_sales_person");
  log.debug("join customer sales person"+JSON.stringify(cust));
  return true; /////////// HERE
      
  if (cust.hasOwnProperty('custrecord_me_join_sales_person')) {
    var salesPerson = cust.getValue('custrecord_me_join_sales_person')[0].value;
    //var salesPerson = currentRecord.getValue({"custrecord_me_join_sales_person"});
    currentRecord.setValue({
      fieldId: 'custbody_me_field_deposit_salesman',
      value: salesPerson
    });
  } else {
    currentRecord.setValue({
      fieldId: 'custbody_me_field_deposit_salesman',
      value: null
    });
  }
              
}              
}           
}
return { fieldChanged: fieldChanged }
  1. some trailing } seems to persist, you may have not properly copy / pasted your code
  2. you return true (exiting gracefuly without any errors or logs, like you told) before having the opportunity to perform your currentRecord.setValue()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM