Javascript stringsplit not working as expected in Client script for a mobile screen refresh.
I’m trying to split a string variable based on a character ‘/’ and return only what precedes that character. So serial# 12345/01 will only return 12345
I get no errors from the script below in mobile; however the fields in mobile are not getting populated with any results.
In example below the alert does not even pop up as blank:
var serialId = ‘12345/01’;
var serialSplit = stringSplit(serialIdt0],'/'); alert(stringFormat("{0}",serialSplit));
Page 1 / 1
Hello @qquac ,
FSM Client scripts are only supported for certain functions, and unfortunately, 'stringsplit' is not one of them. However, you can address this issue using an SQLite query by getDBValue, as shown below.
SELECT SUBSTR('12345/01', 1, INSTR('12345/01', '/') - 1) AS Result;
I hope this helps you.
Thanks you,
Hari
Hello @Hariharan.P ,
I’m replying on behalf of qquac - we both work at the same company.
The use of the stringSplit function in client scripts is referenced as a solution in another question posted on this forum:
Also, the function appears to be active because it highlights in purple within the client script.
Running this in SQLite is not a solution, because this is for a mobile screen refresh.
Let me know if i’m missing something?
Thanks, CJ
Hi @Jacksonc ,
You are correct; this function is only available for Web Client scripts and not for mobile. You can view the reference scripts by right-clicking on the script selections. Since I noticed that you requested implementation for mobile, I recommended the above approach.
The following scripts are applicable for mobile where you cannot find the 'stringsplit'.
The following scripts are applicable for Web client where you can see the 'stringsplit' here.
Hope this helps.
Regards,
Hari
Thanks for the quick reply @Hariharan.P
I see what you mean, and that explains why this function highlights, and appears enabled, within client scripts, but does not work with mobile scripts.
So is there some other solution to my original problem. Within a mobile script how can i parse out the characters I need from a variable? E.g. var serialId = ‘12345/01’; I would only want the characters preceding the ‘/’ so in this case: ‘12345’
Hi @Jacksonc ,
As I mentioned, we can use SQLite along with a custom field to achieve this. If you are implementing this solution solely for display purposes, you can create a custom field and populate it on screen refresh by following the steps below. This approach allows you to split and display your values on the screen.
Var serialID= getControlValue("table_name", “serial_id”);
var serialIDCust = getDBValue(stringFormat("SELECT SUBSTR('{0}', 1, INSTR('{0}', '/') - 1) AS Result", serialID));
You’ve lost me there.. I have only ever used client scripts within the FSM smart client app for refreshing mobile screens. How would i have the mobile app point towards an SQLite script to refresh the screen of a mobile user out in the field?
fyi, yes I do have a custom field created for this already, thanks.
Hi @Jacksonc ,
SQLite is the database used in mobile applications, and FSM Mobile incorporates an SQLite database within the application for mobile data storage. SQLite queries within this context do not interact with a server database; instead, they operate within the mobile application's database, returning values directly.
Client scripts configured in the Client application for mobile application are imported during installation and function within the mobile application itself. Therefore, these scripts execute queries inside the mobile database, functioning similarly to JavaScript and returning values within the mobile application.
Hope this helps.
Thanks,
Hari
@Hariharan.P I did not even realize i could use SQLite within these client scripts. This opens up a lot of possibilities.
Thanks so much for taking the time to explain this in easy to understand terms.