cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPQ Quote 2.0: How to add the Current DateTime to a Custom Quote Field (IronPython Script)?

Alexander_0001
Participant
0 Kudos
1,365

Dear fantastic SAP Community,

I work at the moment with CPQ 2208 & Quote2.0

We wan't to catch the current timestamp in a CustomField of a Quote when a Custom Action will be triggered:

Manny thanks to Yogananda Muthaiah (@yoganandamuthaiah) I tried to follow his blog article with an section about the usage of time date at it end (https://blogs.sap.com/2021/12/31/most-commonly-used-iron-python-functions-in-sap-cpq/) This code works fine...

from datetime import datetime<br>start_time = datetime.now()<br>...<br>end_time = datetime.now()<br>Totaltime = ('Duration: {}'.format(end_time - start_time))

But my following adaptation (for my purpose) produces the Error "can't assign to function call"

from datetime import datetime

Timestamp = datetime.now()
Trace.Write(Timestamp)

FormatedTimestamp = ("{}".format(Timestamp))
Trace.Write(FormatedTimestamp)

context.Quote.GetCustomField("ApprovalModDateCompliance") = FormatedTimestamp<br>


I think the error will becaused by the following code line:

context.Quote.GetCustomField("ApprovalModDateCompliance") = FormatedTimestamp


The Output for Timestamp and FormatedTimestamp can you see here:

2022-08-25 10:32:44.418 (1 ms)Script Execution - Debug run
2022-08-25 10:32:44.418
2022-08-25 10:32:44.418
Local variables in script
-------------------------
Timestamp: datetime (Full type name: IronPython.Modules.PythonDateTime+datetime)
day : 25
hour : 10
microsecond : 418000
minute : 32
month : 8
second : 44
tzinfo : null
year : 2022
-------------------------
FormatedTimestamp: String (Full type name: System.String)
value : 2022-08-25 10:32:44.418000
-------------------------


I have tried a lot of code variants and I didn't found a solution for it, but maybe someone of you know the right code to pass a datetime in a custom field of a quote with the format Date.

Do you have a working version of that code snipet or a hint how to fix it?

Look forward to your support 🙂

Kind regards
Alexander

Accepted Solutions (1)

Accepted Solutions (1)

Alexander_0001
Participant
0 Kudos

Solved by the direct comment of:

lukapilipovic

Many thanks also for the reply to:
yoganandamuthaiah and

The answer which worked for my issue was:

from System import DateTime
CurrentDate = DateTime.Now
context.Quote.GetCustomField("ApprovalModDateCompliance").Value = CurrentDate

Answers (3)

Answers (3)

yogananda
Product and Topic Expert
Product and Topic Expert
import datetime

today_date = datetime.date.today()
print(today_date)

new_today_date = today_date.strftime("%d/%m/%Y")
print (new_today_date)

context.Quote.GetCustomField("Quote Expiration Date").Value = new_today_date

use this for quote 2.0 alexander-maerz lukapilipovic

sbslmhmt
Participant

Hello alexander-maerz ;

Could you try below code;

from System import DateTime

CurrentDate = DateTime.Now

context.Quote.GetCustomField("ApprovalModDateCompliance").Content = CurrentDate


I think you should put ".Content" after context.Quote.GetCustomField("ApprovalModDateCompliance").

Best regards.

Alexander_0001
Participant

Hi Mehmet!
first of all: Wow thank you very much for your fast reply 🙂

I have tried your code sniped. Unfortunately the following error occured:
'Quote2CustomField' object has no attribute 'Content'




I have also tried with the custom field format free form but it the same error is the same 😕

Kind regards
Alexander

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos

alexander-maerz

you can close this question

Alexander_0001
Participant
0 Kudos

Thanks for the reminder 🙂

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos

alexander-maerzThanks, We get notifications for open question regularly.