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

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

LukaPilipovic
Advisor
Advisor

Hi Alexander,

There are multiple layers for discussion here but immediate issue is that you are trying to assign to an object that has type Quote2CustomField while actually you should be assigning to .Value propery of same object.

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

This also will not work as you are trying to assing a string to a DateTime.

Additional considerations needed are if this should be rendered on UI as cpq has many user personalization settings available.

Maybe better approach would be to come up with a full problem statement and than maybe someone can provide bright idea how this should be done in CPQ manner πŸ˜‰

Alexander_0001
Participant

lukapilipovic you are my savior of the evening! I am celebrating you! πŸ™‚

This is now the working code:

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

Result within the quote after Custom Field has been updated.:


Yes you are right but at the moment it is just to test a concept. πŸ™‚

Thank you very much Luka!

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.