Advanced Script - Start Process 2

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
Gabbitas
Posts: 334
Joined: Sun Jan 03, 2010 3:36 am

Advanced Script - Start Process 2

Post by Gabbitas »

Hi All,

I've been going round in circles for a while now and cant work this one out..have searched the forum, looked in user guide and programmer's ref but cant work it out!

I'm trying to get a process to run when a form is displayed. The process requires the same business object that is being displayed to be passed in as context. I can't work out how to pass the business object in as context (how do I get the object ID into the parameters of the function)?

This is the script placed in the init script of the business object form

AwareApp.startProcess2('NameOfMyProcess','BusinessObjectName',NEED_TO_GET_OBJECT_ID_HERE,'main')

Anyone know how I might achieve this?

Thanks
BLOMASKY
Posts: 1470
Joined: Wed Sep 30, 2015 10:08 pm
Location: Ocala FL

Re: Advanced Script - Start Process 2

Post by BLOMASKY »

Maybe I am not understanding what you are trying to accomplish, but why not have a process find the record you want, call your special process then display the form

i.e.

FIND BO WHERE ....
YourSpecialProcess
VIEW BO using YourForm

bruce
Gabbitas
Posts: 334
Joined: Sun Jan 03, 2010 3:36 am

Re: Advanced Script - Start Process 2

Post by Gabbitas »

I could do as you suggest and this is my plan b. The trouble with plan b is that makes for a lot of work. The editing form for this particular business object is called form lots and lots of different places all over my application. To do as you suggest would mean running the ‘load my form’ process in lots of places. If I can get my ‘special process’ to work in the script of the form it’s just one change to make in the config tool.

Thanks for considering this for me though 👍
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: Advanced Script - Start Process 2

Post by Rennur »

I think it's just:

AwareApp.startProcess2('NameOfMyProcess','BusinessObjectName',{ID},'main')

It identifies ID for context in queries, haven't tested it in objects
hpl123
Posts: 2579
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Advanced Script - Start Process 2

Post by hpl123 »

Another solution if the curly tag one doesn't work is hardcoding the id hidden e.g in the form header and then use JS to find the id, assign it to a JS variable which you then use in your aware function. This assumes the JS to get ID and run aware function is a render script.
Henrik (V8 Developer Ed. - Windows)
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: Advanced Script - Start Process 2

Post by aware_support »

Starting a process when a form is displayed is not a good idea generally (depending on what the process is doing it may or may not work)

Why do you need to run a process? What does this process do?
Aware IM Support Team
Gabbitas
Posts: 334
Joined: Sun Jan 03, 2010 3:36 am

Re: Advanced Script - Start Process 2

Post by Gabbitas »

Thanks Rennur but that didn’t work, my gut tells me it should be that simple but is the syntax is off just a little.....?

Henrik, your idea sounds good but my JS knowledge doesn’t stretch that far! Any idea where I could find an example of something similar?

Thanks both
Gabbitas
Posts: 334
Joined: Sun Jan 03, 2010 3:36 am

Re: Advanced Script - Start Process 2

Post by Gabbitas »

Hi Support,

The idea is that when the form is displayed a process is run that compares the data held in AwareIM with the data held in Xero. If the data in AwareIM is out of date then a REST call is made to update the data as the form is displayed.

More often than not the data held in AwareIM would most likely be up to date as a scheduled process is run at night to check if any changes were made in Xero. However, a nightly process doesn’t guarantee the data isn’t out of date.

It’s easy to push changes made in AwareIM to Xero but a bit more challenging to get changes that were made in Xero. Webhooks would solve this issue but I don’t think AwareIM supports them.

Thanks
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: Advanced Script - Start Process 2

Post by aware_support »

You shouldn't do it with Javascript - it won't work. Plan B that Bruce suggested is the only option.

I also think that syncing data automatically is not a good idea either (especially doing it before the form is displayed). I would probably provide a separate button that would explicitly sync the data, so that the user knows what's going on.
Aware IM Support Team
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: Advanced Script - Start Process 2

Post by aware_support »

Also, Aware IM does support web hooks, which is just callback URL's. All you need to is define Aware IM services that will handle calls from Xero. Each service will be automatically exposed on a particular URL that you need to provide as a web hook.
Aware IM Support Team
hpl123
Posts: 2579
Joined: Fri Feb 01, 2013 1:13 pm
Location: Scandinavia

Re: Advanced Script - Start Process 2

Post by hpl123 »

Gabbitas wrote: Mon Nov 09, 2020 12:03 am Thanks Rennur but that didn’t work, my gut tells me it should be that simple but is the syntax is off just a little.....?

Henrik, your idea sounds good but my JS knowledge doesn’t stretch that far! Any idea where I could find an example of something similar?

Thanks both
Well, I do concur with support that doing this might not be the best way and I would personally also do something like Bruce´s suggestion (or better yet the webhook idea) but IF you want to try what I suggested, here are the general things (scribbled down so not thoroughly tested etc.):

1. Create a hidden div with the ID in the form header: <div id="myhiddeniddiv" style="display:none"><<Object.ID>></div>
2. Use JS to find the div and assign value to variable: var objectidvalue=$("#myhiddeniddiv").text();
Source: https://api.jquery.com/text/
3. Use the variable in the aware function: AwareApp.startProcess2('NameOfMyProcess','BusinessObjectName',objectidvalue,'main')
Henrik (V8 Developer Ed. - Windows)
Post Reply