Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 962

Deep insert with 1-1 posting multiple times while flush

$
0
0

Hi Team,

 

We are developing an application using offline store in native iOS. While trying to do a deep insert with 1-1 relation using offline store, it is posting twice to the backend while flushing. But the entry is created only once in the offlinestore.

The code which I used is :

 

                SODataEntityDefault *parentEntity = [[SODataEntityDefault alloc] initWithType:@"MerchReview"];                [parentEntity setResourcePath:@"MerchReviews" editResourcePath:@"MerchReviews"];        [[DataController shared].offlineStore allocatePropertiesOfEntity:parentEntity mode:SODataRequestModeCreate error:&anError];        SODataPropertyDefault* reviewKey = [[SODataPropertyDefault alloc] initWithName:@"MerchReviewKey"];        [reviewKey setValue:string_id];        [[parentEntity properties] setObject:reviewKey forKey:reviewKey.name];                SODataPropertyDefault* visitKey = [[SODataPropertyDefault alloc] initWithName:@"VisitKey"];        [visitKey setValue:@""];        [[parentEntity properties] setObject:visitKey forKey:visitKey.name];                SODataPropertyDefault* customerName = [[SODataPropertyDefault alloc] initWithName:@"CustomerNo"];        [customerName setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"SELECTEDDEALERNO"]];        [[parentEntity properties] setObject:customerName forKey:customerName.name];                SODataPropertyDefault* loginID = [[SODataPropertyDefault alloc] initWithName:@"LoginID"];        [loginID setValue:[[NSUserDefaults standardUserDefaults] objectForKey:@"USERNAME"]];        [[parentEntity properties] setObject:loginID forKey:loginID.name];                SODataPropertyDefault* reviewDate = [[SODataPropertyDefault alloc] initWithName:@"ReviewDate"];        [reviewDate setValue:paymentDate];        [[parentEntity properties] setObject:reviewDate forKey:reviewDate.name];                SODataPropertyDefault* reviewType = [[SODataPropertyDefault alloc] initWithName:@"ReviewType"];        [reviewType setValue:@"01"];        [[parentEntity properties] setObject:reviewType forKey:reviewType.name];                SODataPropertyDefault* reviewLatitude = [[SODataPropertyDefault alloc] initWithName:@"ReviewLatitude"];        [reviewLatitude setValue:latitudeValue];        [[parentEntity properties] setObject:reviewLatitude forKey:reviewLatitude.name];                SODataPropertyDefault* reviewLongitude = [[SODataPropertyDefault alloc] initWithName:@"ReviewLongitude"];        [reviewLongitude setValue:longitudeValue];        [[parentEntity properties] setObject:reviewLongitude forKey:reviewLongitude.name];                SODataPropertyDefault* remarks = [[SODataPropertyDefault alloc] initWithName:@"Remarks"];        [remarks setValue:[txtField_Remarks.text length]>0?txtField_Remarks.text:@""];        [[parentEntity properties] setObject:remarks forKey:remarks.name];                        /**********/        SODataEntityDefault *entityForCreation = [[SODataEntityDefault alloc] initWithType:@"SFGW.MerchReviewImage"];                [entityForCreation setResourcePath:@"MerchReviewImages" editResourcePath:@"MerchReviewImages"];        [[DataController shared].offlineStore allocatePropertiesOfEntity:entityForCreation mode:SODataRequestModeCreate error:&anError];                SODataPropertyDefault* propVisitKey = [[SODataPropertyDefault alloc] initWithName:@"MerchRevImageKey"];        [propVisitKey setValue:string_id];        [[entityForCreation properties] setObject:propVisitKey forKey:propVisitKey.name];                SODataPropertyDefault* propRoutePlanKey = [[SODataPropertyDefault alloc] initWithName:@"MerchReviewKey"];        [propRoutePlanKey setValue:string_id];        [[entityForCreation properties] setObject:propRoutePlanKey forKey:propRoutePlanKey.name];                SODataPropertyDefault* propLoginID = [[SODataPropertyDefault alloc] initWithName:@"MimeType"];        [propLoginID setValue:@"JPEG"];        [[entityForCreation properties] setObject:propLoginID forKey:propLoginID.name];                SODataPropertyDefault* propDate = [[SODataPropertyDefault alloc] initWithName:@"Size"];        [propDate setValue:[NSString stringWithFormat:@"%d", imageSize]];        [[entityForCreation properties] setObject:propDate forKey:propDate.name];                SODataPropertyDefault* propVisitType = [[SODataPropertyDefault alloc] initWithName:@"Image"];        [propVisitType setValue:imageString];        [[entityForCreation properties] setObject:propVisitType forKey:propVisitType.name];                    NSError *error = nil;        [[DataController shared].offlineStore allocateNavigationProperties:parentEntity error:&error];                NSString* const resourcePath = [NSString stringWithFormat:@"MerchReview(%d)", [string_id intValue]];        [parentEntity setResourcePath:resourcePath editResourcePath:resourcePath];        NSObject* navigationProperty = [(id<SODataEntity>)parentEntity navigationPropertyForRelationIdentifier:@"MerchReviewImages"];                id<SODataNavigationProperty> imageNavigationProperty = (id<SODataNavigationProperty>)navigationProperty;                [imageNavigationProperty setNavigationContent:entityForCreation];        [parentEntity setNavigationProperty:imageNavigationProperty forRelationIdentifier:@"MerchReviewImages"];        NSString *finishedSubscription = [NSString stringWithFormat:@"com.sap.sdk.request.delegate.finished"];        // send notification for the finished request                [[NSNotificationCenter defaultCenter] addObserverForName:finishedSubscription object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {                        if(networkStatus == 2)            {                UIAlertView *alt_view  = [[UIAlertView alloc] initWithTitle:@"mSFA" message:@"We are unable to make a internet connection at this time. Some functionality will be limited until a connection is made." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];                [alt_view show];                [self hide_indicator];                            }            else            {                                                [self show_indicator];                dispatch_async(dispatch_get_global_queue(0, 0), ^{                    [[DataController shared].offlineStore scheduleFlushQueuedRequestsWithDelegate:[DataController shared]];                    dispatch_async(dispatch_get_main_queue(), ^{                        [self hide_indicator];                                                                    });                });                            }                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"mSFA" message:@"Review created successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];            [alert show];                                                        }];                [[DataController shared].offlineStore scheduleCreateEntity:parentEntity collectionPath:@"MerchReviews" delegate:[DataController shared] options:nil];

Same behaviour is noticed in Android also.

 

SDK Version is SP11.

 

Regards,

Dhani


Viewing all articles
Browse latest Browse all 962

Trending Articles