Forums › Cached › CSV Import
This topic contains 14 replies, has 0 voices, and was last updated by Cloud 12 years, 4 months ago.
-
AuthorPosts
-
May 17, 2012 at 3:18 am #23866
CloudHi,
I have checked the import types but cannot see on, is there a way to import promotion codes?
We are getting promotion codes from Groupon and there are about 400, and to upload them will take at least a day…
Thanks
Mayur
—— Update…
Found my answer… only enchancement right now
This is a cached copy. Click here to see the original post. -
May 18, 2012 at 12:26 am #23867
jblanchardHi Mayur,
Thanks for your post. That enhancement is targeted for 2012.2. At that point, you should be able to import single-use promotion codes and associate them with the same overall promotion record. You'll also be able to track which customer received which code and whether or not it's been used.
Thanks,
Jeremy
-
June 16, 2012 at 8:46 pm #23868
felix.guinetHi Cloud,
Given the number of records to import, the time it takes to manually create it and the fact that you might receive new promotion codes later, here is what I would do :
1) Create a custom record that contains fields you want to import for Promocodes.
2) Import your data using CSV import, as Custom records are CSV Importable.
3) Script :
Either a) Deploy a fairly simple User Event script on afterSubmit of your Custom Record that will create the associated Promotion code.
Or b) Run once a scheduled script that will go trough all your Custom Records and create appropriate Promotion codes, all at once.
As per the script, you'll need to use something like the following :
var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('code', value_in_the_custom_record);
…
nlapiSubmitRecord(promoCodeRecord );
I hope this will help you!
-
June 25, 2012 at 5:17 am #23869
CloudHi Felix,
Sorry just found time to write this.. thanks for the advise, so far I created this code from your sample code :
PHP Code:
function saveRecord()
{
var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('custrecord_promotion_code', 'Promotion Code');
promoCodeRecord.setFieldValue('custrecord_promo_description', 'Promotion Description');
promoCodeRecord.setFieldValue('custrecord_promo_discount', 'Promotion Discount');
promoCodeRecord.setFieldValue('custrecord_apply_discount', 'Promotion Apply Discount');
promoCodeRecord.setFieldValue('custrecord_promo_start', 'Promo Start');
promoCodeRecord.setFieldValue('custrecord_promo_end', 'Promo End');
promoCodeRecord.setFieldValue('custrecord_promo_all_customers', 'Promo Available All Customers');
promoCodeRecord.setFieldValue('custrecord_promo_item', 'Item');nlapiLogExecution('DEBUG', 'custrecord_promotion_code', 'Promotion Code');
nlapiSubmitRecord(promoCodeRecord);
}Assuming I Read properly from your Sample Script but to clarify
promoCodeRecord.setFieldValue('custrecord_promotion_code', 'Promotion Code');
The Red Text is the Custom Record Field ID and the Blue is the Actual Name of the Custom Record Field and also this is also the Field Label in my CSV Test.
Hope that makes sense. lol..
I imported a test upload but it failed with this error :
Account: 1111189
Environment: Production
Date & Time: 6/25/2012 11:54 am
Record Type: Promotion Code – MR
Internal ID: 101
Execution Time: 0.45s
Script Usage: 5
Script: Bulk Promotion Code Import
Type: User Event
Function: saveRecord
Error: USER_ERROR
Please enter value(s) for: Promotion Code Stack Trace: saveRecord(Bulk_Promo_Code.js:15)
Do you know where I'm going wrong?
See below Screenshot of what field I've created.
-
June 26, 2012 at 9:25 am #23870
Cloudbump..please anyone?
-
June 28, 2012 at 1:21 am #23871
m_cheungRE: Import Promotion Codes
Quote:
promoCodeRecord.setFieldValue('custrecord_promotio n_code', 'Promotion Code');
The Red Text is the Custom Record Field ID and the Blue is the Actual Name of the Custom Record Field and also this is also the Field Label in my CSV Test.
using nlapiSetFieldValue(); the parameters are 1.field id 2.value to set
So in this case I think you want to do
PHP Code:
promoCodeRecord.setFieldValue('custrecord_promotion_code', 'PROMO');
where 'PROMO' is the code you want customers to enter/validate against
To further explain:
promoCodeRecord.setFieldValue('custrecord_promo_de scription', 'Promotion Description');
could be
PHP Code:
promoCodeRecord.setFieldValue('custrecord_promo_description', 'This promotion code gets you 20% off your order and can only be used once');
-
June 28, 2012 at 6:10 am #23872
CloudThanks Michael for the reply.
but isn't my code already doing that?
PHP Code:
var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('custrecord_promotion_code', 'Promotion Code');
promoCodeRecord.setFieldValue('custrecord_promo_description', 'Promotion Description');the 'Promotion Code' & 'Promotion Description' are fields on a CSV. I thought when I upload the CSV I would map the fields on the CSV to the Custom Records I've created and then it would use the actual data promo codes etc..,
Am I making sense? lol..
Thanks
-
June 28, 2012 at 6:35 am #23873
m_cheungRE: Import Promotion Codes
Oh I see what you're saying
In that case you'll need a loop mechanism to read each row of the CSV file and generate a new promo record at each iteration with that row's data
Like
PHP Code:
for(var i=; i<CSV_FILE.length; i++)
{
var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('custrecord_promotion_code', CSV_FILE[i].Code);
promoCodeRecord.setFieldValue('custrecord_promo_description', CSV_FILE[i].Description);
promoCodeRecord.setFieldValue('custrecord_promo_discount', CSV_FILE[i].Discount);
promoCodeRecord.setFieldValue('custrecord_apply_discount', CSV_FILE[i].Apply Discount);
promoCodeRecord.setFieldValue('custrecord_promo_start', CSV_FILE[i].Start);
promoCodeRecord.setFieldValue('custrecord_promo_end', CSV_FILE[i].End);
promoCodeRecord.setFieldValue('custrecord_promo_all_customers',CSV_FILE[i].Available);
promoCodeRecord.setFieldValue('custrecord_promo_item', CSV_FILE[i].Item);
nlapiSubmitRecord(promoCodeRecord);
}
-
June 28, 2012 at 6:44 am #23874
CloudMichael,
Do I change the CSV_FILE to my CSV file name? or do I leave it as it is? Sorry I'm not good with scripting..still trying to learn
Thanks
—-
I got a syntax error :
Title UNEXPECTED_ERROR
Type System
Date & Time 28/6/2012 1:45 pm
Details syntax error (Bulk_Promo_Code.js#3)
-
June 28, 2012 at 7:46 am #23875
m_cheungRE: Import Promotion Codes
Oh sorry, that was pseudocode and not intended for production –
It will be easier just to stick to one method of importing – i.e. either using csv imports or building a script
The CSV import route will be the easiest as @felix.guinet explained
1) Create a custom record that contains fields you want to import for Promocodes.
2) Import your data using CSV import, as Custom records are CSV Importable.
So first create your CSV with 400 rows of promo records – a column for each of the fields you have in your custom record 'Promotion Code – MR'
Use the CSV import assistant to map the columns of your CSV to the fields on your 'Promotion Code – MR'
Run the import and all 400 rows will create a record of your type 'Promotion Code – MR' each with the data you specified in the csv
So to sum up – each row in your CSV becomes a new 'Promotion Code – MR' record
-
June 28, 2012 at 8:25 am #23876
CloudOh Sh** thought I needed both..
ok so just uploaded 2 test codes they imported successfully.. but are not in the Promotion Code page.. don't know what's happened.
—– Update
Never mind, found them.. Thanks
-
June 28, 2012 at 8:44 am #23877
CloudFound 3 problems :
1) Promotion codes I create do not appear under Promotions Page.
2) Normal promotion codes have a Item subtab page to specify which items are included in this promotion… don't know how to display this on mine
3) tested my test promo code – with my Test Item (it should only be linked to this Test Item as I've specified in my CSV but guess it doesn't work – see 2.)
Coupon code is invalid or unrecognised
Please correct or remove the coupon code.
-
July 17, 2012 at 1:04 pm #23878
felix.guinetRE: Import Promotion Codes
Hey Cloud,
How are you doing with this topic? Here is the recap of steps to follow. Do not hesitate to ask for more details:
1) CSV import your list of promotions codes into a custom record. This will create custom records, not yet Netsuite Promotion codes. That may be explaining why you don't find your own promo codes in Netsuite.
2) Run a script that will transform each custom record into a Netsuite Promotion Code record.
-> For the script, you can chose either a User Event Script on afterSubmit of your Custom Record or a Schedule Script to process all custom records in batch.
To throw in some code, the script (in User event, aftersubmit) would look something like this:
Code:
function afterSubmitCreatePromoCode(type){
var my_code = nlapiGetFieldValue('custrecord_promotion_code');
var my_description = nlapiGetFieldValue('custrecord_promo_description');
…var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('code', my_code);
promoCodeRecord.setFieldValue('description', my_description);
…
var id = nlapiSubmitRecord(promoCodeRecord);nlapiLogExecution('debug', 'creation', 'id='+id);
}
Hope this helps,
Cheers!
-
July 18, 2012 at 6:48 am #23879
CloudHi Felix,
really not doing good
ok, so I've written more of your test script this is what I've got :
PHP Code:
function afterSubmitCreatePromoCode(type)
{
var my_code = nlapiGetFieldValue('custrecord_promotion_code');
var my_description = nlapiGetFieldValue('custrecord_promo_description');
var my_discount = nlapiGetFieldValue('custrecord_promo_discount');
var my_apply_discount = nlapiGetFieldValue('custrecord_apply_discount');
var my_start = nlapiGetFieldValue('custrecord_promo_start');
var my_end = nlapiGetFieldValue('custrecord_promo_end');
var my_available_customers = nlapiGetFieldValue('custrecord_promo_all_customers');
var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('Promotion Code', my_code);
promoCodeRecord.setFieldValue('Description', my_description);
promoCodeRecord.setFieldValue('Discount', my_discount);
promoCodeRecord.setFieldValue('Apply Discount To', my_apply_discount);
promoCodeRecord.setFieldValue('Start Date', my_start);
promoCodeRecord.setFieldValue('End Date', my_end);
promoCodeRecord.setFieldValue('Available to all Customers', my_available_customers);
var id = nlapiSubmitRecord(promoCodeRecord);
nlapiLogExecution('debug', 'creation', 'id='+id);}
To Explain – promoCodeRecord.setFieldValue('Promotion Code', my_code);
The Red is the name of the fields when you manually create promotion codes and Blue is the VAR (the custom record) which has the information that needs to be injected.
Am I doing this right? or should it be internal ID's?
I even tested the code and it came back with —
Account: 1111189
Environment: Production
Date & Time: 7/18/2012 1:41 pm
Record Type: Promotion Code – MR
Internal ID: 1401
Execution Time: 0.31s
Script Usage: 5
Script: Bulk Promotion Code Import
Type: User Event
Function: afterSubmitCreatePromoCode
Error: USER_ERROR
Please enter value(s) for: Promotion Code Stack Trace: afterSubmitCreatePromoCode(Bulk_Promo_Code.js:23)
-
July 18, 2012 at 7:11 am #23880
CloudHi Felix,
I realized it has to be internal ID and not field name.
so I amended the script.. im sure im missing alot more here.
PHP Code:
function afterSubmitCreatePromoCode(type)
{
var my_code = nlapiGetFieldValue('custrecord_promotion_code');
var my_description = nlapiGetFieldValue('custrecord_promo_description');
var my_discount = nlapiGetFieldValue('custrecord_promo_discount');
var my_apply_discount = nlapiGetFieldValue('custrecord_apply_discount');
var my_start = nlapiGetFieldValue('custrecord_promo_start');
var my_end = nlapiGetFieldValue('custrecord_promo_end');
var my_available_customers = nlapiGetFieldValue('custrecord_promo_all_customers');nlapiLogExecution('debug', 'Apply Discount', 'applydiscountto');
var promoCodeRecord = nlapiCreateRecord('promotioncode');
promoCodeRecord.setFieldValue('code', my_code);
promoCodeRecord.setFieldValue('description', my_description);
promoCodeRecord.setFieldValue('discount', my_discount);
promoCodeRecord.setFieldValue('applydiscountto', my_apply_discount);
promoCodeRecord.setFieldValue('startdate', my_start);
promoCodeRecord.setFieldValue('enddate', my_end);
promoCodeRecord.setFieldValue('ispublic', my_available_customers);
var id = nlapiSubmitRecord(promoCodeRecord);
nlapiLogExecution('debug', 'creation', 'id='+id);}
however now I'm getting this error as well as the old one
Account: 1111189
Environment: Production
Date & Time: 7/18/2012 2:08 pm
Record Type: Promotion Code – MR
Internal ID: 1702
Execution Time: 0.09s
Script Usage: 5
Script: Bulk Promotion Code Import
Type: User Event
Function: afterSubmitCreatePromoCode
Error: INVALID_KEY_OR_REF
Invalid applydiscountto reference key First Sale Only.
Stack Trace: afterSubmitCreatePromoCode(Bulk_Promo_Code.js:24)
-
AuthorPosts
You must be logged in to reply to this topic.