I want to have a script that connects to an internet based server to get some stuff. However I want to be able to override this on a case by case basis so I thought about using a custom field.
I need then to be able to say "If the custom field xxxx is blank then use server yyyy otherwise use the custom field xxx as server name"....
but i dont know how.
I can update a custom field but I cant work out how to read it and more importantly I cant work out the logic.
Can anyone help ?
Can anyone help? Im guessing I must be able to read the custom field somehow rather than just write it.
To read the value out of custom fields just call it like any other variable with #vSystemInfoManual.%your custom variable name%#
Obviously replace the %.....% part
You can just use that variable directly in the if statement, check variable. from there do exists, contains etc....
And should a variable with spaces in the name be enclosed in speech marks?
You can use the below step to read the custom field value
Does the Get Variable - SQL View Data fail if there is no information in the custom field?
edit:// I should probably clarify that by 'no data' I mean a newly created field (ie. field says 'not available').
Near as I can tell, the "Get Variable - SQL View Data" command fails if there is no data in the custom field... here's the exact error I see in the Agent Procedure log when querying a custom field (that exists) for data (that doesn't exist):
FAILED in processing THEN step 6, Get Variable, with error SQL query failed to return data in GetVariable task, SELECT Monitoring Type* FROM vSystemInfoManual WHERE (Machine_GroupID=''[REDACTED]'')
I have opened a Kaseya support case on this issue and will share results if and when I get them.
So, here's what I've discovered:
1) When querying the value of the Custom Field, you can query one of two ways in the Get Variable statement: > vSystemInfoManual/The_Custom_Field_Name > #vSystemInfoManual.The_Custom_Field_Name#
2) You'll not want to have spaces in your Custom Field name (if you compare values to "vSystemInfoManual\I Like Tacos" for example, the comparison will never work because "vSystemInfoManual\I Like Tacos" will always appear blank to the scripting engine (there, just saved you two hours of wanting to step in front of a bus))
3) You should not query the value of the Custom Field until you're sure it has data, otherwise you will get the error below:
With that in mind, I made a list of the possible variables that my Custom Fields (Monitoring_Type* and Patching_Type*) could be: Workstation, Server, Unpopulated or Unknown.
I then used If statements to make sure the value of the Custom Fields are not one of the "acceptable" values mentioned above... and if it's not one of the "acceptable" variables, the Agent Procedure populates the Custom Fields with an "acceptable" starting value of "Unpopulated". It's only after you do this that you can query the Custom Field without getting the error mentioned earlier.
I know it's often easier to see this in action, so here goes.
Hope this helps!
An easy way to find out if a custom field is unpopulated is to read the Custom Field into a procedure variable and then to use a Check Variable IF Statement to check if the procedure variable is less then a* for a Custom Field that could be populated with words or 0* for a Custom Field that could be populated with numbers.
Declare the variable as a constant first with a know default value e.g "No' ... and then create the same variable using the SQL View command making sure the step is set to "continue if fail" . This way if the SQL returns no value at all and the step fails the default value will be the actual value stored in the variable
Because you're calling a SQLView quotes are not allowed, instead use [ ] when using spaces, for example #vSystemInfoManual.[My Custom Field]#
Aaron Engels | Kaseya
Or you can just create your own view in SQL vCustomFields and set it up to handle empty values like you want then you would call it like CustomData.dbo.vCustomFields/FieldValue
does anyone know how to pull data from org custom fields as opposed to agent custom fields?
I assume you are meaning from the system tab orgs/manage custom fields then I don't believe its possible. I tried a few times before and the database for normal custom fields is dbo.vSystemInfoManual where as the Org custom fields are kasadmin.vbo_Organisations_customFields which cant be referenced.
If you really wanted to you could create your own dbo view in the sql backend using databases kasadmin.orgCustomFieldsDef, kasadmin.orgCustomFields and kasadmin.org along with some way to link this to dbo.machNameTab but im not sure its possible. Possibly one of the advanced SQL guys can or maybe i can't see the forest from the tree's but thats all i know.
I'll Post SQL view tomorrow that gets ORG custom fields , and allows you to define a default value , ie if the Custom field has NO value then it will always be the defined default