We have defined an extension on UD105 with 27 custom columns. One of them is called LastModified_c which is a long (64 bit int). Another is a Guid_c which is a unique GUID.
I am also setting
Key1 = Guid_C
Key2 - LastModified_c
and then I was trying to find the latest rows with the following code:
const refreshJobList = (async (fields) => {
const columns = fields.join(',')
let nowish = Number(Tools.timestamp()) - (60 * 1000) //TODO figure out best window
let reply = await Comm.get(MoveURL, 'UD105s', { $filter: `Key2 gt '${nowish}' `, $select: `${columns}` })
//let reply = await Comm.get(MoveURL, 'UD105s', { $filter: `LastModified_c gt 5 ` })
//let reply = await Comm.get(MoveURL, 'UD105s', { $filter: `LastModified_c gt ${nowish} ` })
return reply
})
function timestamp(obj) {
return (Date.now()).valueOf().toString()
}
/**
* EPICOR invoke ODATA Get command - used NPM O.js (odata) library
* @param {string} serviceBO - Busines Object that provides service
* @param {string} args - the ODATA command and any arguments
* @param {json} query - ODATA query object (e.g. {$filter: `UserName eq 'foobar'`})
* @return {string} The next job number
* @public
*/
const get = (async (serviceBO, args, query) => {
let reply = {}
const url = SERVERURL + serviceBO
const options = window.STORE.getState().identity.options
try {
reply = await o(url, options).get(args).query(query)
} catch (error) {
console.log(`Error Code: ${error.status}`)
console.log(`Error URL: ${error.url}`)
const json = await error.json()
const body = JSON.stringify(json, ' ', 4)
console.log(`Error body: ${body}`)
return error
}
return reply
})
The first version sorta works. Key2 is a x(50) string. but it someone knows how to properly compare the incoming timestamp and do a fast compare.
The issue is that I want to keep updating the LastModified using a rowMod
const updateJob = (async (jobData) => {
let row = { ...jobData, RowMod: "U", Company: "TRI" }
let reply = await Comm.post(MoveURL, 'UD105s', row)
return reply
})
and when I change Key2, I get a new record, not an update of the old record. That is sad because I really want the fast search that a index key gives in a data base, and not search all the records by LastModified_c and see if that is .gt. a value.
And even if I tried to do do that (see the last commented line
//let reply = await Comm.get(MoveURL, 'UD105s', { $filter: `LastModified_c gt ${nowish} ` })
this will not work. Epicor Odata converts the gt 13783093438 which is a long and thinks it is supposed to be edm.Int32 and throws and ODATA error that the long value is a syntax error for int32s.
Does this make sense? or do I need to provide more info?