<% #DEFINE MAX_RESULTS 300 && Maximum number of zip codes that this script will return LOCAL AjaxResponse, SearchBen oJSON=NEWOBJECT('json','json.prg') findWhat = upper(allt(transform(nvl(oRequest.form("findWhat"),'')))) && Read the search string from the query string sender = oRequest.form("sender") && Read the search string from the query string vouchertype=upper(allt(transform(nvl(oRequest.form("voucherType"),'')))) AjaxResponse = CREATEOBJECT("Empty") && Create an object, which will be serialized to JSON format in our response AddProperty(AjaxResponse,"HasResults", .F.) &&Add a property that will indicate whether the script returned search results AddProperty(AjaxResponse,"ResultsCount", 0)&&Add a property that will indicate the number of matching zip codes AddProperty(AjaxResponse,"hasError","") AddProperty(AjaxResponse,"tAction","") AddProperty(AjaxResponse,"tsql","") AddProperty(AjaxResponse,"sender",sender) AddProperty(AjaxResponse,"findWhat",findWhat) return 'nothing' do case case sender='itemtosearch' AND vouchertype=[PURCHASE] iF EMPTY(findWhat) tsql=[SELECT distinct TOP 300 itemid as thecode, ALLTRIM(name)+]+[' ? E '+TRANSFORM(stock)+' P '+TRANSFORM(pcost)+' S '+TRANSFORM(sale) as thename FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE NOT EMPTY(name) ] tsql=tsql+[ ORDER BY thename INTO CURSOR searchresults ] ELSE tsql=[SELECT distinct top 500 itemid as thecode, allt(name)+]+[' ?]+findWhat+[' E '+TRANSFORM(stock)+' P '+TRANSFORM(pcost)+' S '+TRANSFORM(sale) as thename FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE ("] tsql=tsql+findWhat+[" $ UPPER(itemid+name+bar_code) or itemid in ( select distinct itemid from ("]+dbclocation+[asctable.dbf]+[") ] tsql=tsql+[ where allt(bar_code)=="]+findWhat+[")) ORDER BY thename INTO CURSOR searchresults ] ENDIF *RETURN tsql &tsql AjaxResponse.tsql=tsql AjaxResponse.ResultsCount=_tally case sender='itemtosearch' AND vouchertype=[SALES] iF EMPTY(findWhat) tsql=[SELECT distinct TOP 300 itemid as thecode, ALLTRIM(name)+]+[' ? E '+TRANSFORM(stock)+' P '+TRANSFORM(pcost)+' S '+TRANSFORM(sale) as thename FROM ("]+dbclocation+[itemmast.dbf") WHERE NOT EMPTY(name) ] tsql=tsql+[ ORDER BY thename INTO CURSOR searchresults ] ELSE tsql=[SELECT distinct top 500 itemid as thecode, allt(name)+]+[' ?]+findWhat+[' E '+TRANSFORM(stock)+' P '+TRANSFORM(pcost)+' S '+TRANSFORM(sale) as thename FROM ("]+dbclocation+[itemmast.dbf") WHERE ("] tsql=tsql+findWhat+[" $ UPPER(itemid+name+bar_code) or itemid in ( select distinct itemid from ("]+dbclocation+[asctable.dbf[") ] tsql=tsql+[ where allt(bar_code)=="]+findWhat+[")) ORDER BY thename INTO CURSOR searchresults ] ENDIF &tsql AjaxResponse.tsql=tsql AjaxResponse.ResultsCount=_tally OTHERWISE iF EMPTY(findWhat) tsql=[SELECT distinct TOP 300 itemid as thecode, ALLTRIM(name)+]+[' ? E '+TRANSFORM(stock)+' P '+TRANSFORM(pcost)+' S '+TRANSFORM(sale) as thename FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE NOT EMPTY(name) ] tsql=tsql+[ ORDER BY thename INTO CURSOR searchresults ] ELSE tsql=[SELECT distinct top 500 itemid as thecode, allt(name)+]+[' ?]+findWhat+[ E '+TRANSFORM(stock)+' P '+TRANSFORM(pcost)+' S '+TRANSFORM(sale) as thename FROM ("]+dbclocation+[itemmast.dbf]+[") WHERE ("] tsql=tsql+findWhat+[" $ UPPER(itemid+name+bar_code) or itemid in ( select distinct itemid from ("]+dbclocation+[asctable.dbf") ] tsql=tsql+[ where allt(bar_code)=="]+findWhat+[")) ORDER BY thename INTO CURSOR searchresults ] ENDIF RETURN tsql &tsql AjaxResponse.tsql=tsql AjaxResponse.ResultsCount=_tally endcase oResponse.ContentType = "text/plain" IF BETWEEN(AjaxResponse.ResultsCount, 1, MAX_RESULTS) AjaxResponse.HasResults = .T. oJSON.keyforcursors="searchresults" oResponse.Write(oJSON.AddJSONProps(oJSON.stringify(AjaxResponse),oJSON.stringify('SearchResults'))) ELSE oResponse.Write(oJSON.AddJSONProps(oJSON.stringify(AjaxResponse),"")) ENDIF * send JSON data and properties back oResponse.Flush lcHTMLout=[] %>