Splitting a string

Splitting a string

rusty.bird
Advocate Advocate
392 Views
5 Replies
Message 1 of 6

Splitting a string

rusty.bird
Advocate
Advocate

Hello, I need some help with some JavaScript code.   I am trying to edit my setup-sheet-excel-2007.cps to split a string.  I am trying to split the document-path so that It outputs the firstpart of the string only seperated by the first space.  For example I have this document-path string "IDB-765-UY MILLING".  I want to output "IDB-765-UY". 

 

The Code Below I have works with the older Post engine(4.6050) But I am currently using the newer post engine(5.87.0.87) and it doesnt work with this.  How can I accomplish this on the newer?  Here is the code:

 

  var partPath = getGlobalParameter("document-path", "");
  var firstPart = partPath.split(' ')[0];
  programInfo["program.partPath"] = firstPart;

 

 

0 Likes
Accepted solutions (1)
393 Views
5 Replies
Replies (5)
Message 2 of 6

rusty.bird
Advocate
Advocate

I think it has to do with the excel file extension in this post file.  I am using a .xlsm file instead of .xlsx .  The newer engine must not support this since this worked on the 4.6050.  The above works using .xlsx .  

3.png     

0 Likes
Message 3 of 6

viacheslav.shapilov
Autodesk
Autodesk

Hello, @rusty.bird Could you please send us your modified post and template for testing? You can do it using direct message, if you don't want to share your post publicly.

 

We added migration code to the new post engine, that should update your post automatically. But migration can fail, if there are some merge conflicts. In this case we can do it manually for you. 


Viacheslav Shapilov
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 4 of 6

rusty.bird
Advocate
Advocate

Here is the post and .xlsm template.  I have attached two posts here. 

 

One post is after the post engine migration, I changed it to use the .xlsm template (AFTER). This way doesn't open up the .xlsm and gives me an error.

 

The other post is letting the post engine migration change the post when already set at .xlsm (BEFORE).  This opens up the template but the splitting doesn't work correctly.

0 Likes
Message 5 of 6

viacheslav.shapilov
Autodesk
Autodesk
Accepted solution

Had a quick look into your posts.

First of all, we have two versions for this post - one for .xlsx templates that uses ExcelJS library and another for .xlsm files that uses the same approach original post. First one will be removed, as we are getting too many issues with it. So, Setup-Sheet-Before.cps is a correct version for .xlsm templates. But I don't see this part in it:

  var partPath = getGlobalParameter("document-path", "");
  var firstPart = partPath.split(' ')[0];
  programInfo["program.partPath"] = firstPart;

May be it was lost during migration. After reinserting split, it seems works fine. If you have some examples, where it does not work as expected, let us know.

BTW, you attached two migrated versions. It would be better to see version before migration, to be sure, it did not loose anything else.


Viacheslav Shapilov
Developer Technical Services
Autodesk Developer Network


0 Likes
Message 6 of 6

rusty.bird
Advocate
Advocate

It is working now.  Looks like as you have said, When I migrated it, it removed these lines that I previously added.  Also found another change that it didn't migrate where I removed the .png file but I also just re-added this in. 

 

Thanks for looking into this.  I wasn't sure if it had to do with the .xlsm extension but glad that it works and that I dont have to change my whole process.   Its also good to know about the two different versions.

 

Here in my original post-processor before the migration just for your reference.