Jump to content

GetAsNumber do I have to use it?


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

Recommended Posts

Hello.

I have a script, which I call with a script parameter, say Task_New is the name of the script.

I pass the parent key into the script so I can create a new task, which will be associated with my Parent Project.

(psuedo code here)

Perform Script [ Task_New ; GetAsText (Projects::prj_ID) ]

In my Task_New script.

I set the prj_ID_FK of the tasks table to whatever the script param value is I passed in above.

Like so:

Set Field [ tasks::prj_ID_FK ; Get (ScriptParameter) ]

as you can see above, the number passed in via the param is text (ex: "050001"

Must I ? say instead of this:

Set Field [ tasks::prj_ID_FK ; Get (ScriptParameter) ]

Say this?

Set Field [ tasks::prj_ID_FK ; GetAsNumber (ScriptParameter) ]

thanks in advance,

Sincerely,

J__

Link to comment
Share on other sites

right parameters can be string values.

But what I am asking is do you have to use the GetAsNumber () on a string when you set that value into a field, which is of type number ? Are there any coercision issues?

thanks,

J__

Link to comment
Share on other sites

If you want the number field to only display the number, then yes, you need to use GetAsNumber. It will set it with the full string otherwise, even though it may treat the result as a number.

Link to comment
Share on other sites

Queue,

thanks for the response. It's not actually a field I display, it's used for a relation as a FK to my Master table.. sorry it's a master - detail relationship. When I create a new detail record i pass as a param the master tables PK ex: GetAsText ( Project::ID_PK )

so i wondered if since Get (ScriptParameter) will be returning this as a string whether there could be any 'wackiness' if I just set the field, rather than saying set field [ tasks::ID ; GetAsNumber ( Get (ScriptParameter) ) ]

So, is it ok then?

thanks,

sincerely,

J__

Link to comment
Share on other sites

If Project::ID_PK is a text field, then you'll want Tasks::ID|Project to be text also. I'm curious why you're using GetAsText when passing the Project's ID. If it's a text field, then GetAsText isn't necessary. If you're trying to retain leading zeroes, it should be a text field also.

Link to comment
Share on other sites

Curious eh? Good question.

The PK field in Projects table is auto increment starting with "0000" and by 1.

Magically I get "0002", "0003" and so on. But the field is of type Number. so when I display it I get leading 0's.

for my UID I add 05 on the front, so I get "050001" - and this is text.

So, this is the field I pass to my Task_New script. I then figure if it's going to be a number, i should say GetAsNumber() , but I suspect (since I am not doing it that way now, that type coercion works)

hope that makes it clearer. What do you think?

thanks,

J__

Link to comment
Share on other sites

A number field with leading zeroes ignores the leading zeroes (at least it does in previous versions; I haven't tested much with 7), so it seems like they should naturally be text anyway. If you use GetAsNumber( ) on "050001", the result is 50001, which may or may not be an issue for you.

Link to comment
Share on other sites

This topic is 7021 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.