arnoudkooi / sn-scriptsync

Use sn-scriptsync in combination with SN Utils to be able to code in VS Code, including all benefits of a full fledged code editor
https://marketplace.visualstudio.com/items?itemName=arnoudkooicom.sn-scriptsync
Other
43 stars 28 forks source link

Getting error when saving workflow from Visual Code #52

Closed hampusfredriksson closed 2 years ago

hampusfredriksson commented 3 years ago

I'm having same issue found in #15

I see the helper tab is up and running and I can press the little sync script icon from workflow advanced tab which sends the code correctly to vs code. Then when I'm saving in vs code I'm getting a notification with this error message: image

Running latest ServiceNow patch and up-to-date with sn synscript from marketplace also.

Let me know if/how I can provide more information or logs.

arnoudkooi commented 3 years ago

This is also about Workflow Script? maybe as a workaround you could open it from sys_variable_value table and sync from there...

arnoudkooi commented 3 years ago

I figured out the way to find the relation (code below), ony to find out that sys_variable_value is maint only, so probably it wont work, I may remove the "save" button from the script field in workflow scripts

        if (field.startsWith('vars.var__')) { //workflowscripts are stored in sys_variable_value
            loadXMLDoc(g_ck, "/api/now/table/sys_variable_value?sysparm_fields=sys_id&sysparm_query=variable=c35ddef20a0a0ba96248a7090eccd518^document_key="
                + data.sys_id, null,
                res => {
                    data.sys_id = res.result[0].sys_id;
                    data.table = 'sys_variable_value';
                    data.field = 'script';
                    client.send(JSON.stringify(data));
                });

        }
arnoudkooi commented 2 years ago

Can you check in the latest version (2.1.0 and SN Utils 5.2.9.0) if it works I made a function that us a BG script. Please check and let me know. Note that you need to refresh browser to see the changes.

V1tamnT commented 2 years ago

Admittedly, I haven't followed all the development changes as closely as I could (a testament to how well this works), but the last I heard, you could not save a script in a workflow. I've never been able to do it and I think I remember seeing multiple discussions where the developer said it would be hard to save this due to the way workflows work.

I'd LOVE to be wrong about this though.

arnoudkooi commented 2 years ago

This was added in todays update @V1tamnT Please check if it works if you can.

V1tamnT commented 2 years ago

I've verified my VS Code ScriptSync extension is v2.1.0 and SNUtils is 5.2.9. The good news is that I no longer get an error when ScriptSync is running and saving to a Run Script activity. However, I am not seeing a change actually being saved to that activity.

I can see in the Helper tab that something is being saved, but it's not really saving. I've refreshed the browser, but I still do not see the change reflected in the activity.

arnoudkooi commented 2 years ago

Thanks for checking. Is it global scope and do you see something in log? Or click the link in helper tab..

V1tamnT commented 2 years ago

Yes, this is global. I didn't look in a ServiceNow log (not sure which one to look at), but there is an entry in the Helper tab saying it saved to ServiceNow. I'd send a screen capture, but I have to be careful not to send too much info related to my company's instances.

arnoudkooi commented 2 years ago

I just published a minor update to SN Utils 5.2.9.1., that is now available. Could you update and check ?

V1tamnT commented 2 years ago

That appears to have done the trick. I can see an entry in the Helper tab where a background script was executed. After closing the activity and reopening it, I see the update.

It worth noting that, as with other scripts, you can save the activity with the Run Script activity modal closed, once you have it loaded in VS Code.

This. Is. Awesome!

arnoudkooi commented 2 years ago

Great, and note while you do have it open, you can quickly refresh with a double-click in an empty space of the header bar image

bjamn commented 2 years ago

WOW!!! This is fantastic. Great work! I am amazed that this functionality is free!! Thank you so much.