Jump to content

Data API Calls and Global Field


This topic is 1213 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I am trying to set a global variable on a layout, then run a find query using the Data API.  I get a successful response to the request to set the global field, but then when I post the find query url, I get no records found.  Is the global variable I set sticking for the subsequent find request?  I'm worried its not and I don't know how to make it stick if that's the case.  Thanks for any ideas.

Link to comment
Share on other sites

oops.  You are correct. I meant to say I need to set a global field value on the layout and then perform a find request which depends on that global field value being set.

The API call seems to set the global field value without error, which will normally results in a few records with values >0 in certain fields on the layout.  When I then try to subsequently perform a find request via the API after setting the global filed value, it responds that there are no records on the layout with value of a certain field >0.  This would only be the case if the global field value was not set when the find was performed I think, so am wondering if the global field loses its value when I make the 2nd API call with the find request.  ie is there some session or scope issue? 

Link to comment
Share on other sites

'{"query":[{"TOTAL_This_Investor_Amount_Owned":">1"}], "sort":[{"fieldName": "PrimaryKey", "sortOrder":"descend"}]}';

This is the find request called after the global field is updated to the specific investor's id successfully.

The url: 'https://'.$dbhost.'/fmi/data/vLatest/databases/'.$dbname.'/layouts/'.$dblayout.'/_find'

Link to comment
Share on other sites

21 hours ago, MortgageLender said:

set the global field value without error, which will normally results in a few records with values >0 in certain fields on the layout.  

This seems to be the key here, how do those fields with values >0 get their value?  Some sort of calculation that involves the global field?

Global fields do keep their value for the duration of the token's session; if my suspicion is correct you are running into a calculation refresh issue.  Which I would tackle at the root by looking at how not to have to calcs and get the desired value another way.

Link to comment
Share on other sites

Thanks for all the help. Here is long summary:  The db structure is a little hairy and I'm not saying I did it the best way but I have a table of loans that contains data about each loan.  I have a table where investors record buying and selling of interests in each loan. ie:  investor id-buyer, investor id-seller, loan id, amount bought/sold, etc, plus a field that contains both the buyer and seller id in it.  I have a relationship between the loans table and the buy-sell table based on the global investor id set in the loans table that scripts set when needed, which is related to the field in the buy sell table that has both buyer and seller id in it.  So the loans table has access to all the buys and sells for a specific investor when the global is set.  There is a field in the loans table that then shows how much of the specific loan is currently owned by the investor entered in the global investor id field in the loans table that changes whenever the value in the global field changes.

All works fine in the client application, but Data API does not work.  To solve the problem I setup a new set of table occurrences so that Data API can just goto a layout and do a find request for investor id without setting a global.

However, I still wonder:  If you set a global field in a table, and when it is set, a few of the calc fields in that table are updated based on the global's relationship, and the values all update fine in the client app., why don't they update in the Data API?  Is it a sessions issue or something in the API?  ie I make one call to set the global, then another call to do a find, but the global is lost or something?  Problem was solved another way, but still not sure why 1st approach did not work.

Thanks very much fore all the help!

Link to comment
Share on other sites

The Data API works as expected in this case.

This setup, with a global field that triggers a relationship to another table, and a calculation field that uses that relationship:

 

image.png.2de56171ea63b61110eb7cf274a86700.png

 

image.png.8ec2c858b4e6cded1d399fe0fa900d83.png

 

I log in with the Data API, get a token then make the call to update that 'number_gn' global:

image.png.bff09191b375a13d297276c85801164a.png

 

If then make another call (using the same token obviously, to stay within the same session ) to get the records from the _GLO table (where the calculation is) I get the proper value to show up

image.png.7b6e89a31bb99e857b76f3de931f4360.png

 

If I make another call to change the global and then another call to get the _GLO record, I get the properly updated value for 'list_c'.

 

So something in your setup isn't triggering the calculation like you think it does.

 

 

 

 

 

 

Link to comment
Share on other sites

Thx very much for the troubleshoot/feedback!  The only troubleshoot I could think to do was to to a) verify that I received "ok" resp when setting the global (which I did) and  b) verify that setting the global and then performing the find directly in the file worked fine(which it did).

Gremlins or maybe weirdness of the relationship calc I setup maybe based on summation of added and subtracted values in related fields etc.  

Link to comment
Share on other sites

The one thing that is odd about your description of the sequence of API calls is the 'find'.  Given that you set a global and that global needs to fire some calcs, you don't need to find a particular record.  Any record of the context where the global lives will do since the global has the same value across all records and thus all calcs based on that should have the same value.  Unless there are other dependencies in your calc that do depend on what record the user is on.  If that is the case then that is probably where it fails and the global is just a red herring.

But a solution that produces unpredictable responses is a clear sign of being in need of a thorough cleanup...

Link to comment
Share on other sites

Well once I have a layout showing all the records in the loans table.  I enter a particular investor's id in the global field.  Now I can see the amount of each loan owned by that particular investor in the "investor balance owned" field for each loan record in the loans table.

Once I have that I want to then eliminate all the loans for which the investor has $0 in the balance owned field.  So I do the find to bring into my web app only the loans he/she actually owns some of.

Looks like I will need to keep at it as one of my webpages will need this to work will post here know if anything clicks.

Link to comment
Share on other sites

This is a classic example of ideally getting those numbers from the most current state after whatever transactions that move the needle have posted.  There really is no reason why this would have to be recalculated over and over again every time you need the numbers.  It's not scalable as the foundation for a web app.  It's not even scalable as a FM-only mechanism.

Inventory is another good example and basically anything to do with accounting (AR, AP... which yours shares a lot of similarities with).

Link to comment
Share on other sites

I think I might have come closer to determining my issue.  For some reason the "PATCH" http Verb does not seem to work for me when I try to change a global or even update a regular field.  It gives {"messages":[{"message":"Resource doesn't support the specified HTTP verb","code":"1704"}],"response":{}}1. 

I think I am having some kind of problem with record updates via the API.  Looks like permissions are ok.  Finds etc. work fine.  Any idea why PATCH verb wouldn't work for record updates?  Thanks again for any ideas.

Link to comment
Share on other sites

I hope the it.  Im trying to just update a regular non global field on a layout now now but still problem:

 

$update_url = 'https://'.$dbhost.'/fmi/data/vLatest/databases/'.$dbname.'/layouts/'.$dblayout.'/records/'.$recordID

Yes.  It was a problem with the URL.  Capital vs small i in a variable name.  I need a break...Thanks for forcing me to dig into the url as the likely cause!!

Link to comment
Share on other sites

This topic is 1213 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.