Author Topic: Script to change custom data fields for specific item CID's  (Read 1226 times)

0 Members and 1 Guest are viewing this topic.

Offline fwatson1990Topic starter

  • Active Member
  • **
  • Posts: 3
  • Country: gb
  • Gender: Male
Hi,

We've had an issue in our database and we had lost custom data information from our parts.

I would like to be able to use a script to automatically insert the correct custom data on our parts dependant on their CID.

My scripting is not the best but something like this is what I am after can anyone help? Thanks.

Code: [Select]
Select item.cid
case 2
item.customdata[1]value. = "Rectangular Ductwork Galvanised"
item.customdata[2]value. = "1.1"

end select

Offline zhenja83

  • Active Member
  • **
  • Posts: 32
  • Country: 00
  • Gender: Male
Re: Script to change custom data fields for specific item CID's
« Reply #1 on: Feb 26, 2024, 08:33:26 AM »
Hi, your script is ok, but it have some syntax mistakes.
Quote
Select item.cid
case 2
item.customdata[1].value = "Rectangular Ductwork Galvanised"
item.customdata[2].value = "1.1"

end select

Offline fwatson1990Topic starter

  • Active Member
  • **
  • Posts: 3
  • Country: gb
  • Gender: Male
Re: Script to change custom data fields for specific item CID's
« Reply #2 on: Feb 28, 2024, 15:18:30 PM »
Thanks a lot for the reply but I am still getting a scripting error message saying -

"Accessing property of NULL Object at line 3 of 'SCRIPT NAME.cod"

I cant seem to crack this...

Code: [Select]
Select item.cid
case 866
item.customdata[1].value = "Rectangular Ductwork Galvanised"
item.customdata[2].value = "1.1"

end select

Offline DotNet

  • .
  • Senior Member
  • ****
  • Posts: 321
  • Country: us
  • Gender: Male
    • MICLOGIC
Re: Script to change custom data fields for specific item CID's
« Reply #3 on: Feb 28, 2024, 16:42:54 PM »
We can't assume that any given custom data exists on any given job item. Make sure the custom data exists first. This should be standard practice when working with custom data.

Code: [Select]
SELECT ITEM.CID

CASE 866

IF NOT ITEM.CUSTOMDATA[1] THEN
    ITEM.ADDCUSTOMDATA[1]
END IF

ITEM.CUSTOMDATA[1].VALUE = "MY VALUE"

END SELECT

Offline fwatson1990Topic starter

  • Active Member
  • **
  • Posts: 3
  • Country: gb
  • Gender: Male
Re: Script to change custom data fields for specific item CID's
« Reply #4 on: Feb 29, 2024, 11:49:42 AM »
SORTED!  ;D

Thanks a lot everyone for contributing. It turns out that my custom ID's start at 2 for some reason and I had just assumed they started at 1 like a normal work place set up...... haha

Anyways, thanks again, knew it would be something stupid....