We get create 50+ jobs per day which require 1 to 5 cost centers most with pre builds.
So what I do is
- Find current section and cost center
-change custom field
-Add due time and adjust due date if required.
-Add required cost centers (deleting original at the same time)
- Add Prebuild to each cost center - This is where is comes unstuck
- add tags
- set status
So when I add the prebuilds they have to go against the new cost centers, but it maintains previous cost center id code and does not apply the prebuild unless I close all excel workbooks and reopen to refresh the connection. I have tried setting both results and httpObject to Nothing.
Below code is used twice, one at either end of the process but on 2nd run retains data from first run.
Any clues?
Thanks
Code: Select all
Sub fIND_new_cc()
Dim httpObject As Object
Set httpObject = CreateObject("MSXML2.XMLHTTP")
Dim OrDer
Dim TBC
Dim rw
Dim openPos As Integer
Dim closePos As Integer
Dim midBit As String
TBC = 2
rw = 2
Dim sEC
Sheets("Data").Select
Do Until ActiveSheet.Cells(TBC, 1).Value = ""
OrDer = ActiveSheet.Cells(TBC, 1).Value
sEC = ActiveSheet.Cells(TBC, 13).Value
sURL = "https://######.simprosuite.com/api/v1.0/companies/0/jobs/" & OrDer & "/sections/" & sEC & "/costCenters/"
sRequest = sURL
httpObject.Open "GET", sRequest, False
httpObject.setRequestHeader "Authorization", "Bearer key"
httpObject.setRequestHeader "Content-Type", "application/json"
httpObject.send
sgetresult = httpObject.responseText
openPos = InStr(sgetresult, ":")
closePos = InStr(sgetresult, ",")
midBit = Mid(sgetresult, openPos + 1, closePos - openPos - 1)
'MsgBox (sgetresult)
ActiveSheet.Cells(TBC, 31).Value = midBit
TBC = TBC + 1
Set sgetresult = Nothing
Loop
Set sgetresult = Nothing
Set httpObject = Nothing
Call Add_PB
End Sub