Suitescript搜索从变量更改为函数。

huangapple go评论79阅读模式
英文:

Suitescript search changing from a var to a function

问题

function invoiceSearchObj() {
    /* {N/search.Filter} */
    var filters = [];

    /* {N/search.Column} */
    var columns = [];

    var filterParams = [
        { name: 'item.type', operator: search.Operator.ANYOF, values: 'Kit/Package' },
        { name: 'trandate', operator: search.Operator.WITHIN, values: '01/01/2023' },
        { name: 'item.custitemitemoriginal', operator: search.Operator.IS, values: 'T' },
        { name: 'status', operator: search.Operator.ANYOF, values: 'CustInvc:B' }
    ];

    /* Add each filter to the search */
    filterParams.forEach(function (params) {
        filters.push(search.createFilter(params));
    });

    columns.push(search.createColumn({ name: 'tranid', summary: search.Summary.MAX, sort: search.Sort.ASC }));
    columns.push(search.createColumn({ name: 'formulatext', summary: search.Summary.MAX, formula: '{item.memberitem}' }));
    columns.push(search.createColumn({ name: 'internalid', join: 'createdFrom', summary: search.Summary.MAX }));

    return search.create({ type: search.Type.INVOICE, filters: filters, columns: columns });
}
英文:

I am comfortable with programming searches in Suitescript as a variable. I am trying to convert to a function with "push" capability - but my javascript is failing..

Here is original code:

   var invoiceSearchObj = search.create({
   type: "invoice",
   filters:
   [
      ["item.type","anyof","Kit"], 
      "AND", 
      ["trandate","within","01/01/2023"], 
      "AND", 
      ["type","anyof","CustInvc"], 
      "AND", 
      ["item.custitemitemoriginal","is","T"], 
      "AND", 
      ["status","anyof","CustInvc:B"]
   ],
   columns:
   [
      search.createColumn({
         name: "tranid",
         summary: "MAX",
         sort: search.Sort.ASC
      }),
      search.createColumn({
         name: "formulatext",
         summary: "MAX",
         formula: "{item.memberitem}"
      }),
      search.createColumn({
         name: "internalid",
         join: "createdFrom",
         summary: "MAX"
      })
   ]
});

Here is where I am at with a function:

function invoiceSearchObj() {
	
	/* {N/search.Filter} */
		var filters = [];
		
		/* {N/search.Column} */
		var columns = [];
	
	filterParams = 
      [
		{name: 'item.type', operator: search.Operator.ANYOF, values: 'Kit/Package'}, 
        {name: 'trandate', operator: search.Operator.WITHIN, values: '01/01/2023'},         
        {name: 'item.custitemitemoriginal', operator: search.Operator.IS, values: 'T'}, 
        {name: 'status', operator: search.Operator.ANYOF, values: 'CustInvc:B'}
		];
   
   /* Add each filter to the search */
		filterParams.forEach(function(params){
			filters.push(search.createFilter(params));
		});
		
	columns.push(search.createColumn({name: 'tranid', summary: search.Summary.MAX, sort: search.Sort.ASC}));	
	columns.push(search.createColumn({name: 'formulatext', summary: search.Summary.MAX, formula: '{item.memberitem}'}));		
    columns.push(search.createColumn({name: 'internalid', join: 'createdFrom', summary: search.Summary.MAX}));	
      
 
   
   return search.create({type: search.Type.INVOICE, filters: filters, columns: columns});
	}

I am getting errors starting with the item.type (tried Kit and Kit/Package) - not sure if this is my coding or the variables I am using..
Thanks in advance!

答案1

得分: 1

你在连接到另一条记录进行筛选时,应该使用连接属性(join property)。

filterParams =
  [
    { name: 'type', join: 'item', operator: search.Operator.ANYOF, values: 'Kit/Package' },
    { name: 'trandate', operator: search.Operator.WITHIN, values: '01/01/2023' },
    { name: 'custitemitemoriginal', join: 'item', operator: search.Operator.IS, values: 'T' },
    { name: 'status', operator: search.Operator.ANYOF, values: 'CustInvc:B' }
  ];
英文:

You should utilize the join property when doing joins to another record for filters.

filterParams =
  [
    { name: 'type', join: 'item', operator: search.Operator.ANYOF, values: 'Kit/Package' },
    { name: 'trandate', operator: search.Operator.WITHIN, values: '01/01/2023' },
    { name: 'custitemitemoriginal', join: 'item', operator: search.Operator.IS, values: 'T' },
    { name: 'status', operator: search.Operator.ANYOF, values: 'CustInvc:B' }
  ];

huangapple
  • 本文由 发表于 2023年4月7日 02:16:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定