yusuke.higashino | 2023-05-24 12:43:46 UTC | #1
I have created a batch file that outputs a .csv file from the GC CLI list command. Most of the data is being output as I expect using the "--transformstr" gotmpl description.
However, I am having trouble retrieving the array specified data contained in the "gc telephony providers edges phones list" output results.
As an example, I have specified "{{(index .lines 0).state}}" as transform for the key "lines[0].state" in the json, but I get the following error
Error Message: Error applying parsed template to data Error applying parsed template to data object: template: tmpl:1:318: executing "tmpl" at <index .lines 1>: error calling index: reflect: slice index out of range
Am I specifying this incorrectly? Has anyone been able to successfully retrieve such data?
charlie.conneely | 2023-05-24 15:10:02 UTC | #2
Hi Yusuke
It looks like your syntax is correct. Perhaps your mistake is not including the -a flag in your command?
For example, the following command works okay for me:
gc telephony providers edges phones list -a --transformstr="{{ range . }} {{ (index .lines 0).state }} {{ end}}"
yusuke.higashino | 2023-05-25 22:36:32 UTC | #3
Hi Charlie
Thanks for your information.
My command has the -a option specification. I simplified the command and now I have more details on the cause.
It does not seem to be a Syntax problem as you say. I simplified the command and specified only line[0].state and was able to get the data. The command that resulted in an error also included data from line[1].state in the command.
line[0].state has data for all phones. line[1].state has data for only a few phones.
I am assuming that this error occurs when the output result contains data that has no value.
If the key name does not contain an array*, the value <no value> is recorded if no data exists. Does it not have the same behavior?
*e.g.: defaultScripts.CALL.id in Queue settings
charlie.conneely | 2023-05-26 11:30:58 UTC | #4
I'm not certain how the go templating language handles null or empty values, but if the problem is coming from some phones not having more than one line, I would recommend looping over the lines array using the {{range}} tags instead of indexing.
yusuke.higashino | 2023-06-02 11:29:51 UTC | #5
Thanks for your advice. I have implemented it with Range.
system | 2023-07-02 11:30:11 UTC | #6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 20100